0

当我运行这段代码时,有一个问题让我很困惑

data Tree a = Nil | Node a (Tree a) (Tree a)
type IntTree = Tree Int
type Counter = State Int

withCounter::Int -> Counter a -> a
withCounter init f = fst(runState f init)

nextCount::Counter Int
nextCount = do
    n <- get
    put (n+1)
    return n

incTree::IntTree -> IntTree
incTree tree = withCounter 1 (IncTree' tree)
incTree' Nil = return 0
incTree' (Node l e r) = do
    newl <- incTree' l
    n <- nextCount
    newr <- incTree' r
    return (Node newl (e+n) newr)

错误如下:

parse error on input '<-'

它似乎在第 27 行提出,即 'n <- nextCount'

有谁知道我为什么会收到这个错误?谢谢 !

4

1 回答 1

4

由于您似乎没有直接复制和粘贴代码,答案可能是您混合了制表符和空格。

不要使用制表符:仅使用空格缩进。

于 2012-09-19T11:02:51.177 回答