[Haskell-cafe] for = flip map

Matthew Steele mdsteele at alum.mit.edu
Thu Mar 29 02:06:28 CEST 2012


On Mar 28, 2012, at 4: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.

That right; I was simply pointing out that the name 'for' is already  
taken by an existing base function.

Things might be more consistant if 'traverse' and 'for' were instead  
called 'mapA' and 'forA' (by analogy with 'mapM' and 'forM').  Then  
one could add 'for = flip map' to base without conflict.  But for some  
reason, that's not the case.

Cheers,
-Matthew




More information about the Haskell-Cafe mailing list