[Haskell-cafe] Re: Do expression definition

Gleb Alexeyev gleb.alexeev at gmail.com
Mon Sep 13 05:45:33 EDT 2010


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<lemming at henning-thielemann.de>:
>>>> 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




More information about the Haskell-Cafe mailing list