[Haskell-cafe] commenting out a line of code
Bernhard Herzog
bh at intevation.de
Tue Nov 15 16:21:51 UTC 2016
On 15.11.2016, David Turner wrote:
> The outer do block should be desugared first, and the `putStrLn "done"` has
> the same indent as the `if` so it gets a semicolon, in that block, meaning
> it looks like this:
>
> main = do
> { if True
> then do
> putStrLn "A"
> else do
> -- putStrLn "B"
> ; putStrLn "done"
> }
That's what one would expect. Except that GHC treats the 'putStrLn "done"' as
part of the do-block in the else branch by default. This is due to the
NondecreasingIndentation extension which is enabled by default (see
https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/bugs.html#context-free-syntax).
With the option -XNoNondecreasingIndentation (or -XHaskell2010) GHC does
produce an error message because of the empty do-block.
Bernhard
More information about the Haskell-Cafe
mailing list