I am trying to make my own "Set" datatype and when I try to declare an insert function the compiler complains about too few arguments:
quantities.hs:12:27:
Expecting one more argument to `Set'
In the type signature for `insert': insert :: Set e -> Int -> Set
How can I correctly define the insert function to add a new element to my set?
Here is what I have so far:
data Set e = Set [e]
mySet :: Set Int
mySet = Set [1, 2, 3, 4, 5]
setLength :: Set e -> Int
setLength (Set s) = length s
empty :: Set e -> Bool
empty (Set s) = if null s then True else False
insert :: Set e -> Int -> Set
insert set value = set : value
main = do print(insert mySet 1)
Setis not a type,Set eis a type. You forgot theein the signature ofinsert.emptyshould be writtenempty (Set s) = null s.if boolean then True else Falseis exactly the same as justboolean.