<p dir="ltr">GHCi is very lax with do blocks; but as far as I know GHC should refuse to compile that snippet and give a diagnosis about an empty do.</p>
<p dir="ltr">- nitrix</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Nov 15, 2016 10:12 AM, "Lana Black" <lanablack@amok.cc> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="en-US" style="background-color:rgb(255,255,255);line-height:initial"> <div style="width:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)">I havve just tested this with ghc8, and surprisingly when B is commented out the last putStrLn is treated as a part of if-else. So, with B commented out the only thing printed out is A and not 'done'.</div> <div style="width:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"><br style="display:initial"></div> <div style="font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"></div> <table width="100%" style="background-color:white;border-spacing:0px"> <tbody><tr><td colspan="2" style="font-size:initial;text-align:initial;background-color:rgb(255,255,255)"> <div style="border-style:solid none none;border-top-color:rgb(181,196,223);border-top-width:1pt;padding:3pt 0in 0in;font-family:Tahoma,'BB Alpha Sans','Slate Pro';font-size:10pt"> <div><b>From: </b>David Turner</div><div><b>Sent: </b>Tuesday, November 15, 2016 1:14 PM</div><div><b>To: </b>Haskell Cafe</div><div><b>Subject: </b>Re: [Haskell-cafe] commenting out a line of code</div></div></td></tr></tbody></table><div style="border-style:solid none none;border-top-color:rgb(186,188,209);border-top-width:1pt;font-size:initial;text-align:initial;background-color:rgb(255,255,255)"></div><br><div id="m_-8808448150928563277_originalContent"><div dir="ltr"><div class="gmail_extra"><span class="m_-8808448150928563277gmail-im" style="font-size:12.8px"><div class="gmail_quote">On 15 November 2016 at 12:53, Doaitse Swierstra <span dir="ltr"><<a href="mailto:doaitse@swierstra.net" target="_blank">doaitse@swierstra.n<wbr>et</a>></span> wrote:<br></div><div class="gmail_quote"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">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.</div></blockquote><div> </div></div></div></span><div style="font-size:12.8px"><span style="font-size:12.8px">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:</span></div><span class="m_-8808448150928563277gmail-im" style="font-size:12.8px"><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">main = do</span><br style="font-size:12.8px"><span style="font-size:12.8px"> { </span><span style="font-size:12.8px">if True</span></div><div><span style="font-size:12.8px"> then do</span><br style="font-size:12.8px"><span style="font-size:12.8px"> putStrLn "A"</span><br style="font-size:12.8px"><span style="font-size:12.8px"> else do</span><br style="font-size:12.8px"><span style="font-size:12.8px"> -- putStrLn "B"</span><br style="font-size:12.8px"><span style="font-size:12.8px"> ; putStrLn "done"</span></div><div><span style="font-size:12.8px"> }</span><span style="font-size:12.8px"><br></span></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div></span><div class="gmail_quote" style="font-size:12.8px"><span class="m_-8808448150928563277gmail-im">On 15 November 2016 at 12:31, Norbert Melzer <span dir="ltr"><<a href="mailto:timmelzer@gmail.com" target="_blank">timmelzer@gmail.com</a>></span> <wbr>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I'm not quite sure, but I'd guess either one of<div><br></div><div>1.) It does not compile at all because of suspicious indentation</div><div>2.) It will just print "A" but not "done" because that is considered beeing in the else-branch.</div></div></blockquote><div><br></div><div><br></div></span><div>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.</div><div><br></div><div><br></div><div><div><font face="monospace, monospace">[linuxadmin@trac-leeds-09-vm01 13:07:57 ~/indent-puzzle ]</font></div><div><font face="monospace, monospace">$ stack build</font></div><div><font face="monospace, monospace">indent-puzzle-0.1.0.0: build</font></div><div><font face="monospace, monospace">Preprocessing executable 'indent-puzzle-exe' for indent-puzzle-0.1.0.0...</font></div><div><font face="monospace, monospace">[1 of 1] Compiling Main ( app/Main.hs, .stack-work/dist/x86_64-linux/<wbr>Cabal-1.22.5.0/build/indent-pu<wbr>zzle-exe/indent-puzzle-exe-tmp<wbr>/Main.o )</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">/home/linuxadmin/indent-puzzle<wbr>/app/Main.hs:5:10: Empty 'do' block</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">-- While building package indent-puzzle-0.1.0.0 using:</font></div><div><font face="monospace, monospace"> /home/linuxadmin/.stack/setup-<wbr>exe-cache/x86_64-linux/setup-S<wbr>imple-Cabal-1.22.5.0-ghc-7.10.<wbr>3 --builddir=.stack-work/dist/x8<wbr>6_64-linux/Cabal-1.22.5.0 build exe:indent-puzzle-exe --ghc-options " -ddump-hi -ddump-to-file"</font></div><div><font face="monospace, monospace"> Process exited with code: ExitFailure 1</font></div><div><font face="monospace, monospace">[linuxadmin@trac-leeds-09-vm01 13:08:00 ~/indent-puzzle ]</font></div><div><font face="monospace, monospace">$ stack ghci</font></div><div><font face="monospace, monospace">indent-puzzle-0.1.0.0: build</font></div><div><font face="monospace, monospace">Preprocessing executable 'indent-puzzle-exe' for indent-puzzle-0.1.0.0...</font></div><div><font face="monospace, monospace">[1 of 1] Compiling Main ( app/Main.hs, .stack-work/dist/x86_64-linux/<wbr>Cabal-1.22.5.0/build/indent-pu<wbr>zzle-exe/indent-puzzle-exe-tmp<wbr>/Main.o )</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">/home/linuxadmin/indent-puzzle<wbr>/app/Main.hs:5:10: Empty 'do' block</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">-- While building package indent-puzzle-0.1.0.0 using:</font></div><div><font face="monospace, monospace"> /home/linuxadmin/.stack/setup-<wbr>exe-cache/x86_64-linux/setup-S<wbr>imple-Cabal-1.22.5.0-ghc-7.10.<wbr>3 --builddir=.stack-work/dist/x8<wbr>6_64-linux/Cabal-1.22.5.0 build exe:indent-puzzle-exe --ghc-options " -ddump-hi -ddump-to-file"</font></div><div><font face="monospace, monospace"> Process exited with code: ExitFailure 1</font></div><div><font face="monospace, monospace">Warning: build failed, but optimistically launching GHCi anyway</font></div><div><font face="monospace, monospace">The following GHC options are incompatible with GHCi and have not been passed to it: -threaded</font></div><div><font face="monospace, monospace">Using main module: 1. Package `indent-puzzle' component exe:indent-puzzle-exe with main-is file: /home/linuxadmin/indent-puzzle<wbr>/app/Main.hs</font></div><div><font face="monospace, monospace">Configuring GHCi with the following packages: indent-puzzle</font></div><div><font face="monospace, monospace">GHCi, version 7.10.3: <a href="http://www.haskell.org/ghc/" target="_blank">http://www.haskell.<wbr>org/ghc/</a> :? for help</font></div><div><font face="monospace, monospace">[1 of 1] Compiling Main ( /home/linuxadmin/indent-puzzle<wbr>/app/Main.hs, interpreted )</font></div><div><font face="monospace, monospace">Ok, modules loaded: Main.</font></div><div><font face="monospace, monospace">*Main> main</font></div><div><font face="monospace, monospace">A</font></div></div><div><span style="font-family:monospace,monospace">*Main></span></div></div></div></div>
<br></div></div>
<br>______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div></div>