NodeType -> Amount -> Node deposit-6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:18:50 25 4
gpt4 key购买 nike

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

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 的右侧关键字,但我仍然收到相同的错误消息。非常感谢您的帮助!

最佳答案

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com