{-# LANGUAGE TypeOperators #-}{-# LANGUAGE FlexibleContexts #-}------------------------------------------------------------------------------- |-- Module : Generics.EMGM.Functions.UnzipWith-- Copyright : (c) 2008 Universiteit Utrecht-- License : BSD3---- Maintainer : generics@haskell.org-- Stability : experimental-- Portability : non-portable---- Summary: Generic function that applies a (non-generic) function to every-- element in a value, splitting the element into two. The result are two-- structurally equivalent values, one with the elements from the first-- component of the splitting function and the other with the elements from the-- second component.---- 'unzipWith' can be seen as the dual of the 'zipWith' function. It has no-- @Prelude@ counterpart.---- See also "Generics.EMGM.Functions.ZipWith".-----------------------------------------------------------------------------moduleGenerics.EMGM.Functions.UnzipWith(UnzipWith(..),unzipWith,unzip,)whereimportPreludehiding(unzip)importGenerics.EMGM.Common------------------------------------------------------------------------------- Types------------------------------------------------------------------------------- | The type of a generic function that takes an argument of one type and-- returns a pair of values with two different types.newtypeUnzipWithabc=UnzipWith{selUnzipWith::a->(b,c)}------------------------------------------------------------------------------- Generic3 instance declaration-----------------------------------------------------------------------------rconstantUnzipWith::a->(a,a)rconstantUnzipWithx=(x,x)runitUnzipWith::Unit->(Unit,Unit)runitUnzipWith_=(Unit,Unit)rsumUnzipWith::UnzipWitha1a2a3->UnzipWithb1b2b3->a1:+:b1->(a2:+:b2,a3:+:b3)rsumUnzipWithra_(La1)=let(a2,a3)=selUnzipWithraa1in(La2,La3)rsumUnzipWith_rb(Rb1)=let(b2,b3)=selUnzipWithrbb1in(Rb2,Rb3)rprodUnzipWith::UnzipWitha1a2a3->UnzipWithb1b2b3->(a1:*:b1)->(a2:*:b2,a3:*:b3)rprodUnzipWithrarb(a1:*:b1)=let(a2,a3)=selUnzipWithraa1(b2,b3)=selUnzipWithrbb1in(a2:*:b2,a3:*:b3)rtypeUnzipWith::EPb1a1->EPb2a2->EPb3a3->UnzipWitha1a2a3->b1->(b2,b3)rtypeUnzipWithep1ep2ep3rab1=let(a2,a3)=selUnzipWithra(fromep1b1)in(toep2a2,toep3a3)rconUnzipWith::ConDescr->UnzipWitha1a2a3->a1->(a2,a3)rconUnzipWith_=selUnzipWithinstanceGeneric3UnzipWithwhererconstant3=UnzipWithrconstantUnzipWithrunit3=UnzipWithrunitUnzipWithrsum3rarb=UnzipWith(rsumUnzipWithrarb)rprod3rarb=UnzipWith(rprodUnzipWithrarb)rcon3cdra=UnzipWith(rconUnzipWithcdra)rtype3ep1ep2ep3ra=UnzipWith(rtypeUnzipWithep1ep2ep3ra)------------------------------------------------------------------------------- Exported functions------------------------------------------------------------------------------- | Splits a container into two structurally equivalent containers by applying-- a function to every element, which splits it into two corresponding elements.unzipWith::(FRep3UnzipWithf)=>(a->(b,c))-- ^ Splitting function.->fa-- ^ Container of @a@-values.->(fb,fc)-- ^ Pair of containers.unzipWithf=selUnzipWith(frep3(UnzipWithf))-- | Transforms a container of pairs into a container of first components and a-- container of second components. This is a generic version of the @Prelude@-- function of the same name.unzip::(FRep3UnzipWithf)=>f(a,b)->(fa,fb)unzip=unzipWithid