
On 09/13/2010 12:38 PM, Thomas Davie wrote:
On 13 Sep 2010, at 10:28, Gleb Alexeyev wrote:
On 09/13/2010 12:23 PM, Michael Lazarev wrote:
2010/9/13 Henning Thielemann
: It means that variables bound by let, may be instantiated to different types later.
Can you give an example, please?
testOk = let f = id in (f 42, f True)
--testNotOk :: Monad m => m (Int, Bool) --testNotOk = do f<- return id -- return (f 42, f True)
Try uncommenting the 'testNotOk' definition.
There's no "later" here at all.
Two seperate definitions in a Haskell program act as if they have always been defined, are defined, and always will be defined, they are not dealt with in sequence (except for pattern matching but that doesn't apply here).
Instead, what's going on here is scoping. The f in testOk is a different f to the one in testNotOkay, distinguished by their scope.
Finally, this is not how you use a let in a do expression, here's how you should do it:
testOk2 :: Monad m => m (Int, Bool) testOk2 = do let f = id return (f 42, f True)
I don't understand, I'm afraid. Michael Lazarev asked for example on the difference between let-bound and lambda-bound values. testNotOk definition mirrors the structure of the testOk definition, but testNotOk is, pardon my pun, not ok, because f is let-bound and, therefore, monomorphic, while f in the first definition is polymorphic. I never implied that definitions are processed in some sort of sequence, nor I stated that the two f's are somehow related.
Thanks
Tom Davie