I am trying to create a recursive function that takes and input List of List that looks like this: [[1,2], [4], [3], [1]] and returns a Bool. It is supposed to check whether all lists include at least one unique number. I am trying to do this recursively using the two function below.
Function that removes all elements from the first list in the second list:
helper :: Eq a => [a] -> [a] -> [a]
helper a b = filter (`notElem` b) a
Main function:
function :: [[Int]] -> Bool
function [] = True
function (x:y:xs) = (not (null r)) and (function (r ++ xs))
where r = helper(x,y)
However, I get these two errors from the compiler:
Couldn't match expected type ‘(t0 Bool -> Bool) -> Bool -> Bool’
with actual type ‘Bool’
The function ‘not’ is applied to three arguments,
but its type ‘Bool -> Bool’ has only one
In the expression: (not (null r)) and (function (r ++ xs))
In an equation for ‘function’:
function (x : y : xs)
= (not (null r)) and (function (r ++ xs))
where
r = helper (x, y)
I am new to Haskell and not fully comfortable with the Haskell syntax.
anddoesn't do what you think, you're looking for&&helper(x,y)is wrong sincehelperdoes not take a pair as argument. Usehelper x yinstead.