[Haskell-cafe] for = flip map
ezra at ezrakilty.net
ezra at ezrakilty.net
Wed Mar 28 23:26:12 CEST 2012
I would very much like to see a standard function for "flip map" along
these lines. I think it would make a lot of code more readable.
Like the OP, I use "for" in my own code. It's unfortunate that
Data.Traversable takes the name with another type. Two options would be
to (a) reuse the name in Data.List and force people to qualify as
necessary, or (b) choose another name for "flip map".
Regarding other possible names: forall is a keyword and forAll is used
by QuickCheck. One possibility would be "foreach".
Ezra
On Wed, Mar 28, 2012, at 10:19 PM, Christopher Done wrote:
> On 28 March 2012 22:05, Matthew Steele <mdsteele at alum.mit.edu> wrote:
> > Doesn't for already exist, in Data.Traversable? Except that for =
> > flip traverse.
>
> Traverse doesn't fit the type of fmap, it demands an extra type
> constructor:
>
> traverse :: (Traversable t,Applicative f) => (a -> f b) -> t a -> f (t b)
>
> fmap :: Functor f => (a -> b) -> f a -> f b
>
> Note the (a -> f b) instead of (a -> b).
>
> E.g.
>
> fmap :: (a -> b) -> [a] -> [b]
>
> can't be expressed with traverse, you can only get this far:
>
> traverse :: (a -> [b]) -> [a] -> [[b]]
>
> Unless I'm missing something.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list