[Haskell-beginners] Why this order of parameters
Martin Vlk
martin at vlkk.cz
Sat Nov 14 19:37:35 UTC 2015
Harald and Kim-Ee, thanks for your explanations.
So in other words the order of parameters naturally follows from the
corresponding equations and is not driven by technical need.
A follow up question.. what do you mean by elements being "naturally
foldable"? Is it that you could just cons them together without any
transformation?
Martin
Kim-Ee Yeoh:
> On Fri, Nov 13, 2015 at 12:49 AM, Martin Vlk <martin at vlkk.cz> wrote:
>
>> 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.
>>
>
> No, that would be foolish. One doesn't simply make the types different to
> distinguish them.
>
> Suppose the elements are already naturally foldable. Then foldr and foldl
> have the same type signature:
>
> foldl, foldr :: (a -> a -> a) -> a -> [a] -> a
>
> But sometimes they are only foldable qua another type. Call it r. If you
> work through Harald's reasoning, you'll arrive at:
>
> foldr :: (a -> r -> r) -> r -> [a] -> r
> foldl :: (r -> a -> r) -> r -> [a] -> r
>
> -- Kim-Ee
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
More information about the Beginners
mailing list