
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

On Thu, 2007-11-22 at 09:19 +0100, Peter Verswyvelen wrote:
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 :-)
Now go and read about 'mdo' (recursive 'do' notation) ;) BTW, don't you get the same behaviour? foo = let x = 1 in let x = 2 in x * x

On Nov 22, 2007 8:19 AM, Peter Verswyvelen
worksFine = if True then putStrLn "True" else putStrLn "False"
This is just an expression, the indentation is inconsequential.
worksNOT = do if True then putStrLn "True" else putStrLn "False"
The first line, "if True", sets the indentation level of the statements in the "do" to two spaces. So this is interpreted as worksNOT = do { if True ; then putStrLn "True" ; else putStrLn "False" } Which is of course illegal.
worksAgain = do if True then putStrLn "True" else putStrLn "False"
Here, the indentation level of the "do" is still two spaces, but then then and else are at a higher indent than that, so they are interpreted as part of the preceding expression. The rules are actually very simple. Luke

On Thu, 22 Nov 2007, Peter Verswyvelen wrote:
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?
That's somehow related to: http://www.haskell.org/pipermail/haskell-prime/2006-October/001771.html

Hello Peter, Thursday, November 22, 2007, 11:19:20 AM, you wrote:
Of course the worksFine function returns an IO action, so has different behavior, but I mean the indentation is different. Is this by design?
to be exact, Haskell "procedure" is just a function returning an action. i recommend you to read http://haskell.org/haskellwiki/IO_inside the exact reason is different layout rules of expressions and "do" construct, as was already described -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (5)
-
Bulat Ziganshin
-
Henning Thielemann
-
Luke Palmer
-
Peter Verswyvelen
-
Thomas Schilling