[Haskell-cafe] for = flip map

Yves Parès yves.pares at gmail.com
Wed Mar 28 23:11:20 CEST 2012


Think of "traverse" as a "mapA", as it's just like Data.Traversable.mapM,
but with the Applicative class constraint instead of the Monad one.
I've always wondered why it isn't called this way, sequenceM equivalent for
Applicatives is sequenceA for instance.

Le 28 mars 2012 22:19, Christopher Done <chrisdone at googlemail.com> a écrit :

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120328/bca7bb81/attachment.htm>


More information about the Haskell-Cafe mailing list