<br><div><span class="gmail_quote">On 10/1/07, <b class="gmail_sendername">PR Stanley</b> <<a href="mailto:email@example.com">firstname.lastname@example.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>> > f x = x + x<br>> > Is the "x" use to create a pattern in the definition and when f is<br>> > called it's replaced by a value?<br>><br>>Those equation-like definitions are syntactic sugar for lambda
<br>>abstractions. f could as well be defined as f = \x -> x + x.<br><br>Please elaborate</blockquote><div><br>First, the<br><br>f x = <br><br>part says that f is a function which takes a single parameter, called x. The other side of the = sign gives the function body: in this case, x + x. This is exactly the same thing that is expressed by the lambda expression
<br><br>\x -> x + x<br><br>This expression defines a function that takes a single parameter called x, and returns the value of x + x. The only difference is that with the lambda expression, this function is not given a name. But you can easily give the function a name (just as you can give any Haskell expression a name) by writing
<br><br>f = \x -> x + x<br><br>In general, writing<br><br>g x y z = blah blah<br><br>is just a shorthand for<br><br>g = \x -> \y -> \z -> blah blah.<br><br>That is, it simultaneously creates a function expression, and assigns it a name.
<br><br>Does that help?<br>-Brent<br></div></div>