haskell - Haskell 案例语句中的 "Possibly incorrect indentation"

标签 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 语句放在自己的行上,并将两个 case 完全缩进到 of 关键字的右侧,但我仍然收到相同的错误消息。非常感谢您的帮助!

最佳答案

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

关于haskell - Haskell 案例语句中的 "Possibly incorrect indentation",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11141272/

相关文章:

haskell - 在haskell中剖析java类文件

haskell - 为什么 `coerce` 不隐式地将 Compose 应用于这些函数?

haskell - 有reactive-banana-gtk吗?

data-structures - 纯函数式数据结构有什么好处?

haskell - Haskell 的 `reads` 在什么情况下会返回多个列表项?

algorithm - 一些有效的方法来实现这种 map 的插入和查找?

haskell - 从页面中删除预告片

postgresql - 如何使用 postgresql simple (Haskell) 插入数组?

haskell - Haskell 中有理数的模式匹配

haskell - MapM 在 haskell 中的结果?