【问题标题】:Haskell - parse error on input `=' [duplicate]Haskell - 输入“=”时解析错误[重复]
【发布时间】:2014-07-19 16:33:31
【问题描述】:

在实现“河内塔”问题的代码时,我收到以下错误消息:

hanoi.hs:4:24: parse error on input `='
Failed, modules loaded: none.

代码如下:

hanoi 1 i j = [(i, j)]
hanoi n i j = hanoi n' i otherT ++ [(i,j)] ++ hanoi n' otherT j
    where   n' = n-1
            otherT = 1+2+3-i-j

有什么想法吗?

【问题讨论】:

  • 好像你有混合制表符和空格。

标签: haskell recursion towers-of-hanoi


【解决方案1】:

您的编辑器和编译器对选项卡的看法不同。避免使用制表符和空格缩进:

hanoi 1 i j = [(i, j)]
hanoi n i j = hanoi n' i otherT ++ [(i,j)] ++ hanoi n' otherT j
    where   n' = n-1
            otherT = 1+2+3-i-j

优秀的编辑器可以设置为在您按 Tab 时自动执行正确数量的空格。

【讨论】:

    猜你喜欢
    • 2016-01-11
    • 2018-05-02
    • 1970-01-01
    • 2013-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-05
    相关资源
    最近更新 更多