[Haskell-beginners] Still confused
michael at orlitzky.com
Mon Jul 1 20:33:28 CEST 2013
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
> 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
> 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.
More information about the Beginners