[Haskell-cafe] Couple of questions about *let* within *do*

Felipe Lessa felipe.lessa at gmail.com
Tue Aug 10 12:49:13 EDT 2010


On Tue, Aug 10, 2010 at 1:40 PM, michael rice <nowgate at yahoo.com> wrote:
> 1) Is there an implicit *in* before the last line above?

The (let ... in ...) construct is an expression, while the (let ...)
inside 'do' is a statement.  The (do ...) itself is an expression.
See the report:

http://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-440003.12
http://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-470003.14

> 2) Within a do "in" the IO monad (or any other monad), can a *let* do
> something like this?
>
>       let x = do   -- in a different monad

Yes =).  For example,

> main = do -- IO monad
>   putStrLn "Hello!"
>   let x = do i <- [1..5] -- list monad (i.e. [])
>              j <- [i..5]
>              return (i*j)
>   mapM print x

--
Felipe.


More information about the Haskell-Cafe mailing list