
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. Se also https://wiki.haskell.org/Common_Misunderstandings Doaitse
Op 15 nov. 2016, om 13:31 heeft Norbert Melzer
het volgende geschreven: 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.
Johannes Waldmann
mailto:johannes.waldmann@htwk-leipzig.de> schrieb am Di., 15. Nov. 2016 um 13:11 Uhr: Dear Cafe - Sometimes, a comment can change the meaning of a program. No? Well, but "commenting out" a line of code certainly does. So, can you guess what this program will output?
main = do if True then do putStrLn "A" else do -- putStrLn "B" putStrLn "done"
I nominate this for inclusion in a hypothetical Haskell equivalent of http://www.javapuzzlers.com/ http://www.javapuzzlers.com/
- J. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. _______________________________________________ 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.