[Haskell-cafe] Assignment, Substitution or what?

Brent Yorgey byorgey at gmail.com
Mon Oct 1 17:33:45 EDT 2007

On 10/1/07, PR Stanley <prstanley at ntlworld.com> wrote:
> > > f x = x + x
> > > Is the "x" use to create a pattern in the definition and when f is
> > > called it's replaced by a value?
> >
> >Those equation-like definitions are syntactic sugar for lambda
> >abstractions. f could as well be defined as f = \x -> x + x.
> Please elaborate

First, the

f x =

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

\x -> x + x

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

f = \x -> x + x

In general, writing

g x y z = blah blah

is just a shorthand for

g = \x -> \y -> \z -> blah blah.

That is, it simultaneously creates a function expression, and assigns it a

Does that help?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071001/ce6f77d4/attachment-0001.htm

More information about the Haskell-Cafe mailing list