[Haskell-cafe] mapFst and mapSnd

Gregory Collins greg at gregorycollins.net
Tue May 28 11:11:09 CEST 2013


On Tue, May 28, 2013 at 10: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)
>

That's Control.Arrow.(***), e.g.:

    ghci> (+3) *** (*5) $ (20,30)
    (23,150)


>
>   mapFst :: (a -> b) -> (a,c) -> (b,c)
>   mapFst f = mapPair f id
>
>   mapSnd :: (b -> c) -> (a,b) -> (a,c)
>   mapSnd = mapPair id
>

That's Control.Arrow.{first, second}:

    ghci> first (+10) (1,1)
    (11,1)
    ghci> second (+10) (1,1)
    (1,11)

G
-- 
Gregory Collins <greg at gregorycollins.net>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130528/2338b681/attachment.htm>


More information about the Haskell-Cafe mailing list