Reputation: 13
Im writing a Haskell function called myElems
that takes two lists of values and returns true if all the values in
the first list are in the second list. E.g., myElems "db" "abcd"
should return true
whereas myElems [1,2] [0,1,3,4]
should return false
.
myElem
function is like this
myElem n [] = False
myElem n (x:xs) = if n == x then True else myElem n xs
this function works just fine but when I try to apply it to myElems function which has this form
myElems xs [] = False
myElems [] ys = False
myElems (x:xs) (y:ys) = if myElem y xs /= myElem x ys then False else myElems (tail xs) (tail ys)
it doesn't work at all.
Upvotes: 0
Views: 4802
Reputation: 61121
I know it's not the exact answer, but how about what Learn You Haskell book recommends:
import qualified Data.Set as Set
Set.fromList [2,3,4] `Set.isSubsetOf` Set.fromList [1,2,3,4,5]
Upvotes: 2
Reputation: 27350
You mean
myElems [] ys = True
myElems (x:xs) ys = if myElem x ys then myElems xs ys else False
Upvotes: 2