[Haskell-cafe] let vs do?

Stefan Holdermans stefan at cs.uu.nl
Fri Jun 29 00:49:09 EDT 2007


Thomas,

>   let x = ... in ...
>
> is only equal
>
>   do x <- ...; ...
>
> in the Identity monad.  Also, why would "do" be more primitive than  
> "let".  That way you would have to use monads everywhere.  Also,  
> let is treated specially by the type checker (IIRC) and there are  
> many, many other reasons not to do that.

As you already hinted at in a later message, this has to do with let- 
bindings being potentially polymorphic and monadic bindings being  
necessarily monomorphic:

   import Control.Monad.Identity
   foo =               let id =          \x -> x  in        (id 'x',  
id 42) -- well-typed
   bar = runIdentity $ do  id <- return (\x -> x) ;  return (id 'x',  
id 42) -- ill-typed

Cheers,

   Stefan


More information about the Haskell-Cafe mailing list