Re: [Haskell-cafe] mapFst and mapSnd

2013-05-31 Thread Alexander Solla
On Thu, May 30, 2013 at 10:56 PM, Tony Morris wrote: > class BinaryFunctor f where > bimap :: (a -> c) -> (b -> d) -> f a b -> f c d > > mapFst = (`bimap id`) > mapSnd = bimap id > There's a bifunctors package with: class Bifunctor f where bimap :: ... first :: a -> b -> f a c -> f b

Re: [Haskell-cafe] mapFst and mapSnd

2013-05-30 Thread Tony Morris
class BinaryFunctor f where bimap :: (a -> c) -> (b -> d) -> f a b -> f c d mapFst = (`bimap id`) mapSnd = bimap id On 31/05/2013 12:16 PM, "Shachaf Ben-Kiki" wrote: > On Thu, May 30, 2013 at 7:12 PM, Shachaf Ben-Kiki > wrote: > > One generalization of them is to lenses. For example `lens` h

Re: [Haskell-cafe] mapFst and mapSnd

2013-05-30 Thread Shachaf Ben-Kiki
On Thu, May 30, 2013 at 7:12 PM, Shachaf Ben-Kiki wrote: > One generalization of them is to lenses. For example `lens` has > "both", "_1", "_2", such that "mapPair = over both", "mapFst = over > _1", etc., but you can also get "fst = view _1", "set _2 = \y' (x,_) > -> (x,y')", and so on. (Since "b

Re: [Haskell-cafe] mapFst and mapSnd

2013-05-30 Thread Shachaf Ben-Kiki
On Tue, May 28, 2013 at 1:54 AM, 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 > > ma

Re: [Haskell-cafe] mapFst and mapSnd

2013-05-29 Thread Carlo Hamalainen
On Tue, May 28, 2013 at 7:46 PM, Dominique Devriese < dominique.devri...@cs.kuleuven.be> wrote: > 2013/5/28 Tikhon Jelvis : > > These are present in Control.Arrow as (***), first and second > respectively. > > Right, thanks. Strange that neither Hayoo nor Hoogle turned these up.. > HLint suggeste

Re: [Haskell-cafe] mapFst and mapSnd

2013-05-28 Thread Emil Axelsson
`mapPair` also exists as `tup2` in patch-combinators: http://hackage.haskell.org/package/patch-combinators / Emil 2013-05-28 16:01, Andreas Abel skrev: See Agda.Utils.Tuple :-) -- | Bifunctoriality for pairs. (-*-) :: (a -> c) -> (b -> d) -> (a,b) -> (c,d) (f -*- g) ~(x,y) = (f x, g y) --

Re: [Haskell-cafe] mapFst and mapSnd

2013-05-28 Thread Andreas Abel
See Agda.Utils.Tuple :-) -- | Bifunctoriality for pairs. (-*-) :: (a -> c) -> (b -> d) -> (a,b) -> (c,d) (f -*- g) ~(x,y) = (f x, g y) -- | @mapFst f = f -*- id@ mapFst :: (a -> c) -> (a,b) -> (c,b) mapFst f ~(x,y) = (f x, y) -- | @mapSnd g = id -*- g@ mapSnd :: (b -> d) -> (a,b) -> (a,d) mapSn

Re: [Haskell-cafe] mapFst and mapSnd

2013-05-28 Thread Petr Pudlák
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) ->

Re: [Haskell-cafe] mapFst and mapSnd

2013-05-28 Thread Dominique Devriese
2013/5/28 Tikhon Jelvis : > These are present in Control.Arrow as (***), first and second respectively. Right, thanks. Strange that neither Hayoo nor Hoogle turned these up.. Dominique ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.h

Re: [Haskell-cafe] mapFst and mapSnd

2013-05-28 Thread Andrew Butterfield
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

Re: [Haskell-cafe] mapFst and mapSnd

2013-05-28 Thread Gregory Collins
On Tue, May 28, 2013 at 10:54 AM, Dominique Devriese < dominique.devri...@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.:

Re: [Haskell-cafe] mapFst and mapSnd

2013-05-28 Thread Tikhon Jelvis
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 exa

Re: [Haskell-cafe] mapFst and mapSnd

2013-05-28 Thread Benjamin Edwards
You might want to look at the arrow type class and the instance for (->). Ben On 28 May 2013 09:56, "Dominique Devriese" < dominique.devri...@cs.kuleuven.be> wrote: > Hi all, > > I often find myself needing the following definitions: > > mapPair :: (a -> b) -> (c -> d) -> (a,c) -> (b,d) > map