[Haskell-cafe] Problems with do notation

Peter Verswyvelen bf3 at telenet.be
Thu Nov 22 03:19:20 EST 2007


worksFine =
  if True
  then putStrLn "True"
  else putStrLn "False"

worksNOT = do
  if True
  then putStrLn "True"
  else putStrLn "False"

worksAgain = do
  if True
    then putStrLn "True"
    else putStrLn "False"

Of course the worksFine function returns an IO action, so has different 
behavior, but I mean the indentation is different. Is this by design?


Also the following is rather strange:

doubleDefError = let x = 1
                x = 2
            in x * x

alsoDoubleDefError = do
  let x = 1
      x = 2
  return (x*x)

doubleDefNOERROR = do
  let x = 1
  let x = 2
  return (x*x)

Now I understand why this is (the second let starts a new invisible 
scope no?), but for newbies, this is all very strange :-)

Cheers,
Peter

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071122/dc6dc943/attachment.htm


More information about the Haskell-Cafe mailing list