[Haskell-cafe] mapFst and mapSnd

Andrew Butterfield Andrew.Butterfield at scss.tcd.ie
Tue May 28 11:35:23 CEST 2013


I have them defined for my stuff.

Generally I find it much quicker  to "roll my own" than to
(1) ask on this list if someone else has done it...
(2) look at arrows or MyFavouriteCategoryTheoryBitOfFPBecauseICantGetAbstractEnough
    and the try to figure out what is going on.

The joy of Haskell is both that rolling your own is often so easy,
and that there are lots of approaches out there that allow you to get abstract as well...


Regards,
  Andrew (Engineering graduate, feet still firmly embedded in concrete :-)



On 28 May 2013, at 09:54, Dominique Devriese 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

--------------------------------------------------------------------
Andrew Butterfield     Tel: +353-1-896-2517     Fax: +353-1-677-2204
Lero at TCD, Head of Foundations & Methods Research Group
Director of Teaching and Learning - Undergraduate,
School of Computer Science and Statistics,
Room G.39, O'Reilly Institute, Trinity College, University of Dublin
                          http://www.scss.tcd.ie/Andrew.Butterfield/
--------------------------------------------------------------------




More information about the Haskell-Cafe mailing list