leledumbo wrote:
consider this partial program:
if n>5 then
  putStrLn "big"
else
  putStrLn "small"

this works fine in hugs, but in ghc I must change it to:
if n>5
  then
    putStrLn "big"
  else
    putStrLn "small"

Actually both of those are valid expressions.

And they both work in hugs and ghc.

The question I imagine you're asking involves layout mode:

do
  if n>5 then
    putStrLn "big"
  else
    putStrLn "small"

this is shorthand for

do { if n > 5 then putStrLn "big" ; else putStrLn "small" }

which is a syntax error. A statement in a do block cannot begin with the keyword "else".

If you indent the else a bit further than it counts and a continuation of the enclosing expression (beginning with if) so it desugars to

do { if n > 5 then putStrLn "big" else putStrLn "small" }

which is fine.

Haskell' is apparently going to include a hack to permit this case. I think that's a poor decision, because including a hack to the layout rule makes it harder to understand and explain the layout rule.

Jules
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to