DEV Community

Discussion on: Little partial application challenge in Haskell

 
kspeakman profile image
Kasey Speakman • Edited

Huh, this works verbatim in F#.

List.map ((+) -1) [-10..0]

No HKT or type classes, so each structure in F# has its own map implementation.

I'm not sure why it doesn't work in Haskell tbh. Possibilities are that (+) is not recognized as integer addition. Or that the negative sign on -1 is parsed as a function.

Thread Thread
 
antonrich profile image
Anton • Edited

Indeed, Haskell is picky.

map (+ (-1)) [-10..0]

is a working solution.

Also there is another one, specifically to address the problem with the minus sign:

map (subtract 1) [-10..0]

Thread Thread
 
kspeakman profile image
Kasey Speakman

Ah. I wonder why -1 requires parens. I also thought that you can turn an inline operator into a regular function by putting parens around it. (And vice versa with back ticks). I guess I should do my own Haskell homework instead of asking here. :)

Thread Thread
 
muttsuri profile image
Muttsuri

If I remember accurately it is because anything that is not a value in haskell is a function.
So without the parentheses it can't know if -1 means the function - applied to some other value and the number one like1-1( function - applied to 1 and 1 ) or the value -1, so the way they solved it is to have it be the function, therefore you would be missing an argument or you would be passning a wrong type.
When you want a value you would have to use (-1) so then it knows that you trully mean the value -1.

PS: This is my first comment I hope I didn't come out sounding a but too "know it all" or trying to sound smart, I just wanted to explain it the best I can.