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
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
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
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
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
`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)
--
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
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) ->
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
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
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.:
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
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
13 matches
Mail list logo