Haskell/解决方案/缩进
外观
练习 |
---|
使用显式花括号和分号重写控制结构章节中的这段代码 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!" |
当然,有很多有效的答案,因为您可以随意缩进代码并换行。以下是一个示例
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!"; }; };