
Hi Brandon, Darren, and Michael, Thanks for you responses, but I'm still confused. Here are two examples of operator sections. The first takes the infix operator / and turns it into a prefix operator. Prelude> let eight_div_by = ((/) 8 ) Prelude> eight_div_by 4 2.0 I get that. But look at the following: We now have a prefix operator with the input on the "wrong" side. Prelude> let div_by_eight = ( / 8 ) Prelude> div_by_eight 4 0.5 Why should ( / 8) 4 = 0.5? Thanks again, Marc

Does it help to think of it like algebra?
let x = 4
where x / 8
On Mon, Jul 1, 2013 at 2:03 PM, Marc Gorenstein
Hi Brandon, Darren, and Michael,
Thanks for you responses, but I'm still confused.
Here are two examples of operator sections. The first takes the infix operator / and turns it into a prefix operator.
Prelude> let eight_div_by = ((/) 8 ) Prelude> eight_div_by 4 2.0
I get that. But look at the following: We now have a prefix operator with the input on the "wrong" side.
Prelude> let div_by_eight = ( / 8 ) Prelude> div_by_eight 4 0.5
Why should ( / 8) 4 = 0.5?
Thanks again,
Marc
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Mon, Jul 1, 2013 at 2:03 PM, Marc Gorenstein
Here are two examples of operator sections. The first takes the infix operator / and turns it into a prefix operator.
Prelude> let eight_div_by = ((/) 8 ) Prelude> eight_div_by 4 2.0
Yes. A section is just this conversion of an infix operator to a prefix function, but with one parameter carried along with it. You can supply it on either side as appropriate; (/ 8) is the same as (\x -> x / 8) which in turn is the same as (\x -> (/) x 8), whereas (8 /) is (\x -> 8 / x) is (\x -> (/) 8 x). Note that it must be *inside* the parentheses to be a section; if it's outside, then it's a normal function (not operator!) parameter. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

Yes. A section is just this conversion of an infix operator to a prefix
function, but with one parameter carried along with it. You can supply it on either side as appropriate; (/ 8) is the same as (\x -> x / 8) which in turn is the same as (\x -> (/) x 8), whereas (8 /) is (\x -> 8 / x) is (\x -> (/) 8 x). Note that it must be *inside* the parentheses to be a section; if it's outside, then it's a normal function (not operator!) parameter.
-- brandon s allbery kf8nh sine nomine associates
Hi Brandon (and others), Thanks very much. I'm no longer confused. I can see that a Section is a special case that turns a binary infix operator turns into a single-parameter prefix function. The equivalence to a lambda abstraction makes it clear. Thanks, Marc

Yes. A section is just this conversion of an infix operator to a prefix
function, but with one parameter carried along with it. You can supply it on either side as appropriate; (/ 8) is the same as (\x -> x / 8) which in turn is the same as (\x -> (/) x 8), whereas (8 /) is (\x -> 8 / x) is (\x -> (/) 8 x). Note that it must be *inside* the parentheses to be a section; if it's outside, then it's a normal function (not operator!) parameter. Thanks again. Now I also understand why Prelude> ( $ 4 ) sqrt 2.0 because it is equivalent to Prelude> (\x -> x 4) sqrt 2.0 Marc

(/ 8)
is the same as
(\x -> x / 8)
you can think of it as
(HERE_IS_SOMETHING_MISSING / 8)
whereas
(/) 8
is normal function currying, i.e. it is the same as
(\x -> (/) 8 x)
or
(\x -> 8 / x)
just like
foo y
is the same as
(\x -> foo y x)
if foo is a function that takes 2 parameters.
on the other hand
(8 /)
is like
(8 / HERE_IS_SOMETHING_MISSING)
which translates to
(\x -> 8 / x)
Am 01.07.2013 um 20:03 schrieb Marc Gorenstein
Hi Brandon, Darren, and Michael,
Thanks for you responses, but I'm still confused.
Here are two examples of operator sections. The first takes the infix operator / and turns it into a prefix operator.
Prelude> let eight_div_by = ((/) 8 ) Prelude> eight_div_by 4 2.0
I get that. But look at the following: We now have a prefix operator with the input on the "wrong" side.
Prelude> let div_by_eight = ( / 8 ) Prelude> div_by_eight 4 0.5
Why should ( / 8) 4 = 0.5?
Thanks again,
Marc
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

I'm a beginner, too, but I look at it this way: (+) is the uncurried,
unsectioned add function. You use (+) when it happens to be convenient or
necessary to use it the way you'd use functions that you give names, e.g.
passing it to another function the way you do with map.
A section, on the other hand, is a partial application of a function, and
the way to remember what happens to the input it takes is to notice which
operand is inside the parentheses of the section.
( / 8) is the function that, given n, returns n / 8.
(8 / ) is the function that, given n, returns 8 / n.
It only really makes a difference when the function in question isn't
commutative.
On Mon, Jul 1, 2013 at 1:03 PM, Marc Gorenstein
Hi Brandon, Darren, and Michael,
Thanks for you responses, but I'm still confused.
Here are two examples of operator sections. The first takes the infix operator / and turns it into a prefix operator.
Prelude> let eight_div_by = ((/) 8 ) Prelude> eight_div_by 4 2.0
I get that. But look at the following: We now have a prefix operator with the input on the "wrong" side.
Prelude> let div_by_eight = ( / 8 ) Prelude> div_by_eight 4 0.5
Why should ( / 8) 4 = 0.5?
Thanks again,
Marc
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On 07/01/2013 02:03 PM, Marc Gorenstein wrote:
Hi Brandon, Darren, and Michael,
Thanks for you responses, but I'm still confused.
Here are two examples of operator sections. The first takes the infix operator / and turns it into a prefix operator.
Prelude> let eight_div_by = ((/) 8 ) Prelude> eight_div_by 4 2.0
I get that. But look at the following: We now have a prefix operator with the input on the "wrong" side.
Prelude> let div_by_eight = ( / 8 ) Prelude> div_by_eight 4 0.5
Why should ( / 8) 4 = 0.5?
This isn't a normal Haskell function application, it's a special case (Brandon pointed at the place in the spec where it's defined.) It does a trick, transforming (/ 8) into "flip (/) 8" so that the argument will wind up in the right place. You've got the 8 on the right-hand side of the division operator, and that's where it stays. It only works for binary operators, since they have a left-hand argument and a right-hand argument. (4 /) will return a function, "four divided by something," and (/ 8) will return a function, "something divided by 8." In both cases, the 4 or the 8 stay on the same side of the division operator. But there's a hidden transformation happening to get the other argument in the right spot.
participants (6)
-
Brandon Allbery
-
James Jones
-
Marc Gorenstein
-
Michael Orlitzky
-
Michael Peternell
-
Ryan Bell