[Haskell-cafe] mapFst and mapSnd
Petr Pudlák
petr.mvd at gmail.com
Tue May 28 15:34:57 CEST 2013
Dne 28.5.2013 10:54, Dominique Devriese napsal(a):
> Hi all,
>
> I often find myself needing the following definitions:
>
> mapPair :: (a -> b) -> (c -> d) -> (a,c) -> (b,d)
> mapPair f g (x,y) = (f x, g y)
>
> mapFst :: (a -> b) -> (a,c) -> (b,c)
> mapFst f = mapPair f id
>
> mapSnd :: (b -> c) -> (a,b) -> (a,c)
> mapSnd = mapPair id
>
> But they seem missing from the prelude and Hoogle or Hayoo only turn
> up versions of them in packages like scion or fgl. Has anyone else
> felt the need for these functions? Am I missing some generalisation
> of them perhaps?
Apart from Arrows, there is also package "bifunctors" that defines this
functionality for (,), Either and a few others:
http://hackage.haskell.org/packages/archive/bifunctors/3.2.0.1/doc/html/Data-Bifunctor.html
Petr Pudlak
More information about the Haskell-Cafe
mailing list