[Haskell-beginners] Why this order of parameters

David McBride toad3k at gmail.com
Thu Nov 12 17:49:11 UTC 2015


He means why is the first argument a -> b -> b in one function but b -> a
-> b in the other.  And I have no answer for that.  I admit to having been
caught by that in the past.  You can't just replace one with the other in
code, you have to do a flip on the operator.

On Thu, Nov 12, 2015 at 12:34 PM, Alex Belanger <i.caught.air at gmail.com>
wrote:

> foldr :: (a -> b -> b) -> b -> [a] -> b
> foldr :: (b -> a -> a) -> a -> [b] -> a
>
> are exactly the same types; simply inverted names for the type variables.
>
> I don't clearly see any benefit.
>
> Alex.
> On Nov 12, 2015 12:00 PM, "Martin Vlk" <martin at vlkk.cz> wrote:
>
>> Hi, my first intuition about this is that in data constructor it
>> technically doesn't matter, but you could argue that "a" represents the
>> actual result of the function so it comes first.
>> Second comes the state, which is the side thing, hence the
>> secondary/less important position.
>>
>> As for the order of type constructor parameters you are right - state is
>> part of the structure that Monoid, Functor, Applicative, Monad and the
>> like use.
>>
>> Martin
>>
>> martin:
>> > runState :: State s a -> s -> (a, s)
>> >
>> > I understand that in the constructor s has to be first, so we can turn
>> (State s) into a monad. But why doesn't s come
>> > first in the result too, as in
>> >
>> > runState :: State s a -> s -> (s, a)
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151112/ca303b83/attachment.html>


More information about the Beginners mailing list