
On 15 November 2016 at 12:53, Doaitse Swierstra
The answer is very simple ;-} The report says that after a do the first symbol to encounter determines the indentation level; so putStrLn “done” is part of the else branch. Obvious, isn’t it.
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"
}
On 15 November 2016 at 12:31, Norbert Melzer
I'm not quite sure, but I'd guess either one of
1.) It does not compile at all because of suspicious indentation 2.) It will just print "A" but not "done" because that is considered beeing in the else-branch.
I get *both* of these behaviours! When building, it complains about an empty 'do' block. When running through `stack ghci` it doesn't seem to mind. [linuxadmin@trac-leeds-09-vm01 13:07:57 ~/indent-puzzle ] $ stack build indent-puzzle-0.1.0.0: build Preprocessing executable 'indent-puzzle-exe' for indent-puzzle-0.1.0.0... [1 of 1] Compiling Main ( app/Main.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/indent- puzzle-exe/indent-puzzle-exe-tmp/Main.o ) /home/linuxadmin/indent-puzzle/app/Main.hs:5:10: Empty 'do' block -- While building package indent-puzzle-0.1.0.0 using: /home/linuxadmin/.stack/setup-exe-cache/x86_64-linux/setup- Simple-Cabal-1.22.5.0-ghc-7.10.3 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.22.5.0 build exe:indent-puzzle-exe --ghc-options " -ddump-hi -ddump-to-file" Process exited with code: ExitFailure 1 [linuxadmin@trac-leeds-09-vm01 13:08:00 ~/indent-puzzle ] $ stack ghci indent-puzzle-0.1.0.0: build Preprocessing executable 'indent-puzzle-exe' for indent-puzzle-0.1.0.0... [1 of 1] Compiling Main ( app/Main.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/indent- puzzle-exe/indent-puzzle-exe-tmp/Main.o ) /home/linuxadmin/indent-puzzle/app/Main.hs:5:10: Empty 'do' block -- While building package indent-puzzle-0.1.0.0 using: /home/linuxadmin/.stack/setup-exe-cache/x86_64-linux/setup- Simple-Cabal-1.22.5.0-ghc-7.10.3 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.22.5.0 build exe:indent-puzzle-exe --ghc-options " -ddump-hi -ddump-to-file" Process exited with code: ExitFailure 1 Warning: build failed, but optimistically launching GHCi anyway The following GHC options are incompatible with GHCi and have not been passed to it: -threaded Using main module: 1. Package `indent-puzzle' component exe:indent-puzzle-exe with main-is file: /home/linuxadmin/indent- puzzle/app/Main.hs Configuring GHCi with the following packages: indent-puzzle GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( /home/linuxadmin/indent-puzzle/app/Main.hs, interpreted ) Ok, modules loaded: Main. *Main> main A *Main>