[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    Re: [Haskell-cafe] Foldable, Traversable and choosing an order
From:       Tom Ellis <tom-lists-haskell-cafe-2017 () jaguarpaw ! co ! uk>
Date:       2019-09-25 18:06:54
Message-ID: 20190925180654.w2wrgtawjy2p6lcf () weber
[Download RAW message or body]

On Wed, Sep 25, 2019 at 06:03:20PM +0100, Juan Casanova wrote:
> why isn't traverse just defined as
> 
> traverse_alt :: (Traversable t, Applicative f) => t (f a) -> f (t a)
> traverse_alt = traverse id
> 
> and let fmap deal with the mapping of the function? Of course this wouldn't
> be the implementation, it would be the other way around. Instances of
> Traversable would implement traverse_alt, and then whenever I wanted to do
> what traverse currently does, I would just do: traverse_alt (fmap f inputs).
> What is there to gain by including the mapping into the traversal *in the
> implementation of traverse itself*?

Your `traverse_alt` is called `sequence`:

    https://hackage.haskell.org/package/base-4.12.0.0/docs/src/Data.Traversable.html#Traversable

They're both useful and you can define each in terms of the other.  I'd say
I use traverse about ten times more than sequence.  It's basically
equivalent to `mapM`, i.e. "map with an effect".  `fmap` followed by
`sequence` tends to read a bit clumsily.

Tom
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic