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" -- View this message in context: http://www.nabble.com/if---then---else-layout-tp19663006p19663006.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
On 2008 Sep 25, at 0:47, 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, this also works: if n > 5 then putStrLn "big" else putStrLn "small" Except in a "do", the "else" must be indented beyond the start of the "if". I think Hugs is violating the Haskell98 layout rules. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
I think you mean "in a do". There is a proposal to fix this in Haskell' cheers, Fraser On Sep 25, 2008, at 6:59, "Brandon S. Allbery KF8NH" <allbery@ece.cmu.edu
wrote:
On 2008 Sep 25, at 0:47, 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, this also works:
if n > 5 then putStrLn "big" else putStrLn "small"
Except in a "do", the "else" must be indented beyond the start of the "if". I think Hugs is violating the Haskell98 layout rules.
-- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
"Brandon S. Allbery KF8NH" <allbery@ece.cmu.edu> wrote:
I think Hugs is violating the Haskell98 layout rules.
One could argue that GHC should, too. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited.
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
Jules Bean <jules@jellybean.co.uk> wrote:
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".
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.
There's no need to hack the layout rule, you're even giving pointers to the solution. Something like this: if p = do (_, c, a) <- get put (b, c, a) mzero then c = do (b, _, a) <- get put (b, c, a) mzero else a = do (b, c, _) <- get put (b, c, a) mzero end = do (b, c, a) <- get return if p then a else c Advantages are obvious: Order doesn't really matter anymore, as in then "get away" else "or else" if i tell you to end Furthermore, this scheme supports logical comments, a rare kind of control structure enabling mindboggingly diverse rapid prototyping options: if i knew what i want to do if i knew how to do it then i'd have written the next line much earlier if i wrote this line then i don't need to remove the other lines else where in other languages i'd have to do that end -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited.
Achim Schneider <barsoap@web.de> wrote:
if i knew how to do it
Sorry, apparent mistake, besides confusing b (bool) with p (predicate): if p _ c = do (_, _, a) <- get put (p, c, a) mzero -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited.
On Wed, 24 Sep 2008, 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"
maybe related http://www.haskell.org/haskellwiki/If-then-else
participants (7)
-
Achim Schneider -
Brandon S. Allbery KF8NH -
Fraser Wilson -
Henning Thielemann -
Jason Dusek -
Jules Bean -
leledumbo