[Haskell-beginners] Question about precedence
David Virebayre
dav.vire+haskell at gmail.com
Tue Jul 2 09:14:19 CEST 2013
> 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.
Exactly. You can get 1+x with a section, just write it (1+)
> Division works the same way.
That's where the subtly different things becomes not so subtle,
because if you define
two_divided_by_1 = (/) 2
two_divided_by_2 = (/ 2)
in the first case you indeed define a function that divides two by the
number given,
but in the second case it's a function that divides the number given by two.
You have to define it like this: two_divided_by_3 = (2 /)
Prelude> let two_divided_by_1 = (/) 2
Prelude> let two_divided_by_2 = (/2)
Prelude> two_divided_by_1 4
0.5
Prelude> two_divided_by_2 4
2.0
Prelude> let two_divided_by_3 = (2/)
Prelude> two_divided_by_3 4
0.5
Prelude>
More information about the Beginners
mailing list