I don't want to solve your problem for you - I believe the solution should be your own work. However, I will provide a list of functions which could assist you, and which you don't have to import:
filter f list
: returns all elements of list
where f element
returns True
. For instance, filter (\x -> (x /= 0)) [0,1,0,2,3]
gives [1,2,3]
. This is useful with the not
function, which inverts a Bool
; for instance, filter (\x -> not (x > 2)) [1,2,3,4,5]
gives [1,2]
.
all f list
: returns True
if f
gives True
for all elements of list
. For example, all (\x -> (x /= 0)) [1,2,3]
gives True
; however, all (\x -> (x /= 0)) [1,0,2,3]
gives False
.
x `elem` list
(which is really just syntax sugar for elem x list
) returns true if x
is an element of list
. For example, 1 `elem` [1,2,3]
gives True
, but 0 `elem` [1,2,3]
gives False
.
Again, I won't directly give you the solution to this problem. But I can guarantee you that if you put the above functions together in the right way - together with the Just
and Nothing
constructors - you can make your complement
function.