I am trying to create a function justifyList that takes a list of Maybe objects ([Maybe a]) and return a list of all objects of Just type, discarding any element that is Nothing in the parameter list.
My solution for now is
justifyList :: [Maybe a] -> [a]
justifyList [] = []
justifyList (x:xs)
| (isNothing x) = justifyList xs
| otherwise = x : justifyList xs
where I try to recursively iterate through the parameter list and recursively put the current element x to the returned list [a], if it is of Just type.
However when interpreting a type mismatch error is generated
Couldn't match type a with Maybe a
Hence my question is; how do I recursively iterate through a list of Maybe objects? If this solution is sufficient, how do I convert xs to be of Maybe type?