我建立在Haskell一組數據類型和我的工作remove函數,我無法得到它的權利,這裏的名單是我的代碼:串聯自定義數據類型
data Set a = Set [a] deriving (Eq,Ord,Show)
remove :: Integer -> Set Integer -> Set Integer
remove _ (Set []) = (Set [])
remove numberToRemove (Set (x:xs))
|x == numberToRemove = Set(xs)
|otherwise = Set(x:remove numberToRemove (Set xs))
我想將x添加到集合中刪除將返回,但我不知道如何使它與我的自定義數據類型一起工作。
這是我的錯誤:
test.hs:13:28:
Couldn't match expected type `[Integer]'
with actual type `Set Integer
In the return type of a call of `remove'
In the second argument of `(:)', namely
`remove numberToRemove (Set xs)'
In the first argument of `Set', namely
`(x : remove numberToRemove (Set xs))'
Failed, modules loaded: none.
感謝
如果您正在爲樂趣這種數據類型中提取回來的說法,對你有好處!如果你只需要一個你正在編寫的代碼的Set數據類型,就已經有[Data.Set'](http://hackage.haskell.org/packages/archive/containers/latest/doc/html/Data-Set的.html) – rampion