【发布时间】:2010-01-20 19:52:28
【问题描述】:
在最近的answer to a style question,我写道
main = untilM (isCorrect 42) (read `liftM` getLine)
和
isCorrect num guess =
case compare num guess of
EQ -> putStrLn "You Win!" >> return True
...
Martijn 有用的建议替代方案:
main = untilM (isCorrect 42) (read <$> getLine)
EQ -> True <$ putStrLn "You Win!"
使用Control.Applicative 的抽象可以使 Haskell 代码中的哪些常见模式更清晰?有效使用 Control.Applicative 时需要记住哪些有用的经验法则?
【问题讨论】:
标签: haskell coding-style