10

All of the examples I've seen so far create a "wrapper" function around Basics.+ and then partially apply that:

sum x y = 
  x + y

plusOne =
  sum 1

However, I'm sure that there's a way to avoid the extra wrapping.

1 Answer 1

13

Wrap it in parenthesis

plusOne =
  (+) 1
3
  • Ah, that must be why the documentation shows the method with parentheses.
    – Shepmaster
    Commented Nov 3, 2015 at 3:11
  • An idea of why it is not (+ 1) like in Haskell ? And why (-) 1 have a very curious behavior... but (+) -1 works has intended :-) Commented Dec 15, 2015 at 13:45
  • 1
    Infix functions are defined a little differently than regular functions. (+ 1) is how you would partially apply a regular function but for infix you have to wrap it in () to make it behave like a regular function first. (-) has the signature number -> number -> number. It subtracts the second number from the first number. (-) 1 partially applies 1 as the first number, so it is the same as f x = 1 - x. If you want it the other way you can use the flip function flip (-) 1 Commented Dec 15, 2015 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.