Re: Proposal: alpha-rename the type signatures of foldl, foldl', and scanl to be consistent with foldr and scanr

Conal Elliott <[email protected]>
Newsgroups gmane.comp.lang.haskell.cvs.ghc,gmane.comp.lang.haskell.libraries
Message-ID <CAD6SzRL21X=D2QzUJUG3B+Q77C_Uy_7u5bUq9G5KPgVmnrji_A@mail.gmail.com>
Amen! (+1).

I often have to rewrite the signature of foldl to the suggested version as
a sanity check. I thought it just was my personal mental deficiency.

I prefer "b" to "r".

-- Conall

On Sun, Oct 14, 2012 at 7:28 AM, Gábor Lehel <[email protected]> wrote:

> Currently we have:
>
>     foldl :: (a -> b -> a) -> a -> [b] -> a
>
>     foldr :: (a -> b -> b) -> b -> [a] -> b
>
> I find this confusing. My brain doesn't do automatic alpha-renaming,
> so I end up thinking that these types are very different because they
> look very different. In fact, they are almost the same.
> Embarrassingly, it took me longer than it took to understand monads,
> GADTs, PolyKinds, and several other things before I realized it!
>
> So I propose that we use 'a' consistently to denote the type of the
> list elements, and 'b' to denote the type of the result:
>
>     foldl :: (b -> a -> b) -> b -> [a] -> b
>
>     foldr :: (a -> b -> b) -> b -> [a] -> b
>
> making it obvious that the only difference is the order of parameters
> to the accumulator.
>
> The total change would be to replace
>
>     Prelude.foldl :: (a -> b -> a) -> a -> [b] -> a
>     Prelude.scanl :: (a -> b -> a) -> a -> [b] -> [a]
>     Data.List.foldl' :: (a -> b -> a) -> a -> [b] -> a
>     Data.Foldable.foldl :: (a -> b -> a) -> a -> t b -> a
>     Data.Foldable.foldl' :: (a -> b -> a) -> a -> t b -> a
>
> with
>
>     Prelude.foldl :: (b -> a -> b) -> b -> [a] -> b
>     Prelude.scanl :: (b -> a -> b) -> b -> [a] -> [b]
>     Data.List.foldl' :: (b -> a -> b) -> b -> [a] -> b
>     Data.Foldable.foldl :: (b -> a -> b) -> b -> t a -> b
>     Data.Foldable.foldl' :: (b -> a -> b) -> b -> t a -> b
>
> I've attached a patch.
>
> Discussion period: 2 weeks
>
> Previously discussed at: http://www.reddit.com/r/haskell/comments/10q2ls/
>
> --
> Your ship was destroyed in a monadic eruption.
>
> _______________________________________________
> Cvs-ghc mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/cvs-ghc
>
>

_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.