Haskell 人不懂缩进

最近更多地了解了一下 Haskell,我觉得语言本身还行。然而,我真的受不了 Haskell 人缩进的方式。拿这个为例子(来自 Haskell wikibook):

doGuessing num = do
   putStrLn "Enter your guess:"
   guess <- getLine
   if (read guess) < num
     then do putStrLn "Too low!"
             doGuessing num
     else if (read guess) > num
            then do putStrLn "Too high!"
                    doGuessing num
            else putStrLn "You Win!"

这么简单的一段代码,仍然让我看着眼睛疼。原因我觉得可以这么解释:

使用“正确”的缩进和对齐,改了函数名,再加上适当的空行后,这段代码变成了这样:

doGuessing num = do

    printLine "Enter your guess:"
    guess <- getLine

    if      (read guess) < num then do
        printLine "Too low!"
        doGuessing num
    else if (read guess) > num then do
        printLine "Too high!"
        doGuessing num
    else
        printLine "You Win!"

这就看起来好多了。

如果你喜欢更多的嵌套,你可以这样写:

doGuessing num = do

    printLine "Enter your guess:"
    guess <- getLine

    if (read guess) < num
        then do
            printLine "Too low!"
            doGuessing num
        else if (read guess) > num
            then do
                printLine "Too high!"
                doGuessing num
            else
                printLine "You Win!"