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.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366

1 Answers1

13

Wrap it in parenthesis

plusOne =
  (+) 1
robertjlooby
  • 7,160
  • 2
  • 33
  • 45
  • Ah, that must be why the documentation shows the method with parentheses. – Shepmaster Nov 03 '15 at 03: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 :-) – Emrys Myrooin Dec 15 '15 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](http://package.elm-lang.org/packages/elm-lang/core/3.0.0/Basics#flip) function `flip (-) 1` – robertjlooby Dec 15 '15 at 15:18