[Haskell-cafe] Minor issue with mapAccumR

Cale Gibbard cgibbard at gmail.com
Wed Feb 6 19:33:46 EST 2008


On 06/02/2008, Ross Paterson <ross at soi.city.ac.uk> wrote:
> On Tue, Feb 05, 2008 at 12:03:38AM -0500, Cale Gibbard wrote:
> > Are many people using mapAccumR? How much would it hurt to change it?
>
> It's specified in the Haskell 98 Report, so changing it is a big deal.
> Personally, I think the types should have been
>
>         mapAccumL :: (s -> a -> (b,s)) -> s -> [a] -> ([b],s)
>         mapAccumR :: (a -> s -> (s,b)) -> [a] -> s -> (s,[b])
>
> to show which direction the state flows.
>
<snip: nice generalisation to Traversable>

However, it's perhaps worth considering as well that ((,) s) is a
Functor instance, something which the MTL ignores in its types, using
less-convenient (a,s) pairs in Writer and State.

 - Cale


More information about the Libraries mailing list