Haskell案例陈述中的“可能不正确的缩进”

时间:2012-06-21 15:15:13

标签: haskell

我一直在为这个缩进愚弄一段时间,但看起来对我来说是正确的。谁能看到我哪里出错了?

deposit :: NodeType -> NodeType -> Amount -> Node
deposit (Income income) (Account bal grow) amount =
  Account (bal + transfer) grow where transfer = case amount of
    AbsoluteAmount amount  -> min income amount -- This is line 34
    RelativeAmount percent -> (min 1.0 percent) * income

我收到的错误消息是:

Prelude> :load BudgetFlow.hs 
[1 of 1] Compiling Main             ( BudgetFlow.hs, interpreted )

BudgetFlow.hs:34:5: parse error (possibly incorrect indentation)
Failed, modules loaded: none.

第34行(包含解析错误的行)是开始AbsoluteAmount的行(我在上面用注释标记了它)。我已经尝试将case语句放在自己的行上并将这两个案例完全缩进到of关键字的右侧,但我仍然得到相同的错误消息。非常感谢您的帮助!

1 个答案:

答案 0 :(得分:4)

where子句放在自己的行上。

deposit :: NodeType -> NodeType -> Amount -> Node
deposit (Income income) (Account bal grow) amount = Account (bal + transfer) grow
    where
        transfer = case amount of
            AbsoluteAmount amount  -> min income amount -- This is line 34
            RelativeAmount percent -> (min 1.0 percent) * income