嘿大家我正在一块Haskell代码,并不能找出如何解决这个问题。Haskell数据类型困境
我得到这个错误:
Couldn't match expected type `Collection' with actual type `[a0]'
In the expression: [list] ++ numberToInsert
In an equation for `insert':
insert numberToInsert (Set [list])
| contains (Set [list]) numberToInsert == True = (Set [list])
| otherwise = [list] ++ numberToInsert
失败,模块加载:无。
这里是我的代码
data Collection = Set [Int] deriving (Show)
insert :: Int -> Collection -> Collection
insert numberToInsert (Set [list])
|contains (Set [list]) numberToInsert == True = (Set [list])
|otherwise = [list] ++ numberToInsert <--- this is my problem
contains :: Collection -> Int -> Bool
contains (Set []) numberToFind = False
contains (Set (x:xs)) numberToFind
|x == numberToFind = True
|otherwise = contains (Set (xs)) numberToFind
有人可以帮我解决这个问题?
谢谢
您是否收到错误?如果是这样,你可以将它添加到你的问题? –
我更新了它。谢谢 – functionalCode
当问一个问题时,您应该尝试详细解释问题是什么,并且包含编译器错误信息 - 我们不应该猜测为什么“这是您的问题”以及如何解决问题。此外,您可以提出有用的问题和答案,并接受令人满意地解释您自己的问题的问题。这有助于组织Stackoverflow。 – hugomg