[Haskell-cafe] mapFst and mapSnd
Tikhon Jelvis
tikhon at jelv.is
Tue May 28 11:01:14 CEST 2013
These are present in Control.Arrow as (***), first and second respectively.
They are easy to overlook because they work for *all* arrows, not just
functions. So the type signatures look like:
first :: Arrow a => a b c -> a (b, d) (c, d)
If you replace a with (->), you'll see that this is exactly like your
mapFst.
On Tue, May 28, 2013 at 1:54 AM, Dominique Devriese <
dominique.devriese at cs.kuleuven.be> wrote:
> 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?
>
> Regards,
> Dominique
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130528/88480726/attachment.htm>
More information about the Haskell-Cafe
mailing list