
What sort of beast is ( / 8) in Haskell? It looks like it is a function that divides a number by 8. *Main> ( / 8 ) 4 0.5 *Main> let a = ( / 8 ) *Main> a 4 0.5 -- Yup that works. Does ( / 8 ) turn into a function that takes an argument, so that the "left" input to the /, becomes a right input to the function? What precedence rule is being followed here? Thanks, Marc

On Mon, Jul 1, 2013 at 12:14 PM, Marc Gorenstein
What sort of beast is ( / 8) in Haskell? It looks like it is a function that divides a number by 8.
It's an operator section. http://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-300003.5d... their syntax and their precedence behavior. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

I think that since infix notation always takes two parameters, the compiler
handles parameter swapping to match the unfilled argument for convenience.
Not sure where this would be described in a spec though.
Cheers,
Darren
On Mon, Jul 1, 2013 at 9:14 AM, Marc Gorenstein
What sort of beast is ( / 8) in Haskell? It looks like it is a function that divides a number by 8.
*Main> ( / 8 ) 4 0.5
*Main> let a = ( / 8 ) *Main> a 4 0.5
-- Yup that works.
Does ( / 8 ) turn into a function that takes an argument, so that the "left" input to the /, becomes a right input to the function? What precedence rule is being followed here?
Thanks,
Marc
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

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.

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>
participants (5)
-
Brandon Allbery
-
Darren Grant
-
David Virebayre
-
Marc Gorenstein
-
Michael Orlitzky