我今天发布了一个问题,有人帮助,但他的代码不工作。这是链接到后link to the post需要帮助修复一个小问题
当我运行他的代码,我得到一个错误:“输入`解析错误'”
的“。”之后“\ t”导致错误。在Haskell中是新的,所以我不知道它为什么会导致错误。
需要帮助解决此问题,但。
感谢
UPDATE
我得到的错误,当我加载代码。这是错误:
Couldn't match expected type `a -> Bool'
against inferred type `[Bool]'
In the first argument of `any', namely
`(map (\ t -> contains t b) c)'
In the second argument of `(||)', namely
`any (map (\ t -> contains t b) c)'
In the expression: a == b || any (map (\ t -> contains t b) c)
需要帮助修复它。
感谢
UPDATE
当我进行更改后,运行该代码:
data Tree a = Leaf a | Branch a [(Tree a)] deriving (Show)
contains :: Tree a -> a -> Bool
contains (Leaf a) b = a == b
contains (Branch a c) b = a == b or (map (\ t -> contains t b) c)
这是错误我现在得到:
Occurs check: cannot construct the infinite type:
a = ([Bool] -> Bool) -> [Bool] -> a
When generalising the type(s) for `contains'
更新3
请这是我的代码,但我做了所有更改后仍然出现错误。我不明白:
data Tree a = Leaf a | Branch a [(Tree a)] deriving (Show)
contains :: Eq a => Tree a -> a -> Bool
contains (Leaf a) b = a == b
contains (Branch a c) b = a == b || (map (\t -> contains t b) c)
布尔不能在我的系统上工作,所以我必须使用布尔。现在这是我得到的错误:
Couldn't match expected type `Bool' against inferred type `[Bool]'
In the second argument of `(||)', namely
`(map (\ t -> contains t b) c)'
In the expression: a == b || (map (\ t -> contains t b) c)
In the definition of `contains':
contains (Branch a c) b = a == b || (map (\ t -> contains t b) c)
如果它能工作,请运行上面的代码。或者,也许我错过了某个地方。 我非常感谢你的时间。我很感激。
感谢
这是一个错字,methinks(`\ t。(...)`不是有效的Haskell,`\ t - >(...)` - 用有效的替换省略号,当然),他已经修好了。 – delnan 2010-12-03 15:54:25