[Haskell-beginners] Question about precedence
Michael Orlitzky
michael at orlitzky.com
Mon Jul 1 18:44:15 CEST 2013
On 07/01/2013 12:14 PM, Marc Gorenstein wrote:
> What sort of beast is ( / 8) in Haskell? It looks like it is a function
> that divides a number by 8.
>
Yep. This is probably easier to think about with addition rather than
division.
So, (+) is a function. It takes two arguments, and adds them. You need
the parenthesis to prevent it from being an infix operator (used in
*between* the numbers), but that's just a detail. Try it in ghci:
ghci> (+) 1 2
3
Thanks to currying, you can construct a function called "plus_one" by
leaving off the last argument:
ghci> let plus_one = (+) 1
ghci> let plus_one = (+ 1)
Either notation will work, but they do subtly different things: in the
first case, you get 1 + x, and in the second, you get x + 1. Nevertheless.
ghci> plus_one 2
3
Division works the same way.
More information about the Beginners
mailing list