大家好,我正在尝试在Haskell中创建一个集合数据类型,但是我无法弄清楚如何实现。以下是我目前的代码,我有些困惑:
data Set a = Node a | List {
list :: [a]
}deriving(Eq,Show,Ord)
insert :: Set Integer -> Set Integer -> Bool
insert (Node itemToInsert) (List list)
|contains (List list) (Node itemToInsert) == False = List(list:(Node itemToInsert))
contains :: Set Integer -> Set Integer -> Bool
contains (List []) (Node numberToFind) = False
contains (List (x:xs)) (Node numberToFind)
|x == (Node numberToFind) = True
|otherwise = contains (List (xs)) (Node numberToFind)
感谢您的帮助!