Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Haskell/Solutions/Indentation

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Explicit characters in place of indentation Rewrite this snippet from the Control Structures chapter using explicit braces and semicolons: doGuessing num = do putStrLn "Enter your guess:" guess <- getLine case compare (read guess) num of LT -> do putStrLn "Too low!" doGuessing num GT -> do putStrLn "Too high!" doGuessing num EQ -> putStrLn "You Win!" There are of course many valid answers, given that you can indent the code and break the lines however you wish. Here is one of them: doGuessing num = do { putStrLn "Enter your guess:"; guess <- getLine; case compare (read guess) num of { LT -> do { putStrLn "Too low!"; doGuessing num; }; GT -> do { putStrLn "Too high!"; doGuessing num; }; EQ -> putStrLn "You Win!"; }; };