How do I use a let within a do block in ghci?

ghci, haskell

Solution

Try this:

let a = do let { b = 5 } ; print b 

The `let` block can contain multiple declarations so you have to tell GHCi when they're done - that's what the brackets are for in this line.

By the way, you can use `print` for `putStrLn . show`.

Problem

I'm trying to create a do block interactively in ghci. As long as I don't define a variable with in block, it's fine: ``` Prelude>let a = do putStrLn "test"; putStrLn "other test" Prelude> ``` but I can't figure out how to define a let construction in the do block interactively without getting a parse error: ``` Prelude> let a = do let b = 5; putStrLn $ show b <interactive>:2:40: parse error (possibly incorrect indentation or mismatched brackets) ``` Obviously ``` let a = do let b = 5 putStrLn $ show b ``` is entirely fine in a Haskell source file. I'm just having trouble figuring out how to translate that to ghci.

Original source