[Haskell-cafe] commenting out a line of code

Alex Belanger i.caught.air at gmail.com
Tue Nov 15 15:15:24 UTC 2016


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.

- nitrix

On Nov 15, 2016 10:12 AM, "Lana Black" <lanablack at amok.cc> wrote:

> 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'.
>
> *From: *David Turner
> *Sent: *Tuesday, November 15, 2016 1:14 PM
> *To: *Haskell Cafe
> *Subject: *Re: [Haskell-cafe] commenting out a line of code
>
> On 15 November 2016 at 12:53, Doaitse Swierstra <doaitse at swierstra.net>
>  wrote:
>
>> 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 <timmelzer at gmail.com> wrote:
>
>> 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 at 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-pu
> zzle-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-S
> imple-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 at 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-pu
> zzle-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-S
> imple-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>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161115/2c9fbba1/attachment.html>


More information about the Haskell-Cafe mailing list