[Haskell-beginners] some insights into functional programming

Magnus Therning magnus at therning.org
Tue Aug 11 01:51:42 EDT 2009

Michael P Mossey wrote:
> Thanks for the ideas, Adam. I still have a few questions.
> Adam Bergmark wrote:
>> The reason my is available in the lambda \x -> my >>= \y -> W (x+y) has to
>> do with scoping rules, Haskell (and almost all programming languages) use
>> static scoping, meaning a variable defined in an outer function is
>> available in the inner function, for instance, (\a -> \b -> (a,b)) 1 2 will
>> evauate to (1,2) since a is bound to 1 in the outer lambda, and the inner
>> one can refer to the outer one, if instead you write (\a -> \a -> (a,a)) 1
>> 2 the result will be (2,2) since the innermost a will be used (no ambiguity
>> here, but  if shadowing is done by accident it can be hard to find the
>> error).
> Because the lambda is executed by the implementation of >>=, doesn't the
> concept closure still apply? That value of 'my' has to "get into" the other
> routine.

I think you are both right.  AFAIU Adam comments on *visibility* of the
variables, while you look more at the fact that you pass the lambda as an
argument to (>>=).  The lambda can "see" the variable my due to scoping, and
(>>=) can trigger evaluation of the lambda due to closures.

I'm looking forward to be corrected by someone who knows more about this than
I do.


Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
Url : http://www.haskell.org/pipermail/beginners/attachments/20090811/303059f8/signature.bin

More information about the Beginners mailing list