我今天發佈了一個問題,有人幫助,但他的代碼不工作。這是鏈接到後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