[Haskell-beginners] Still confused
James Jones
jejones3141 at gmail.com
Mon Jul 1 20:23:45 CEST 2013
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
<marc.gorenstein at gmail.com>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?
>
>
> Thanks again,
>
> Marc
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130701/8c5d2217/attachment.htm>
More information about the Beginners
mailing list