[Haskell-beginners] Why this order of parameters
Harald Hanche-Olsen
hanche at math.ntnu.no
Thu Nov 12 20:45:37 UTC 2015
Hmmm, I seem to have missed part of this conversation, but I’ll toss in my two cents anyhow:
Consider the identities
foldl (•) s [x,y,z] == ((s•x)•y)•z
foldr (•) s [x,y,z] == x•(y•(z•s))
and I think it should be clear that the type of (•) must be a→b→a in the former and b→a→a in the latter.
Either of these identities would look rather odd when written in operator notation if (•) were flipped!
– Harald
-----Original Message-----
From: Martin Vlk <martin at vlkk.cz>
Date: 12 November 2015 at 18:49:35
> I think again this technically doesn't matter...
>
> I'm curious if this could be for the sake of making the types of the two
> functions (foldr/foldl) different? E.g. so that you can tell from the
> type what function it is.
>
> (I'm a Haskell beginner myself so would be curious to hear an expert's
> voice on this!)
>
> Martin
>
> martin:
> > foldl :: (a -> b -> a) -> a -> [b] -> a
> > foldr :: (a -> b -> b) -> b -> [a] -> b
> >
> > For once the list is a list of as in foldl, but a list of as in foldr. Now that can be fixed
> with renaming the type
> > parameters
> >
> > foldr :: (b -> a -> a) -> a -> [b] -> a
> >
> > this is the exact same thing and resembles more the type of foldl. But still the function
> argument has its parameters
> > flipped. foldl's function takes the list element as second parameter and foldr's takes
> it as first parameter.
> >
> > Why is that so?
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
Harald Hanche-Olsen
Førsteamanuensis
Institutt for matematiske fag
Norges teknisk-naturvitenskapelige universitet
7491 Trondheim
http://www.math.ntnu.no/~hanche/
More information about the Beginners
mailing list