Answer the question
In order to leave comments, you need to log in
How to determine if a list is a sublist?
Hello, I have a task: There are two lists. Determine if the first list is a sublist of the second.
I wrote the code, it looks like it should work, but it doesn't. Can anyone suggest what I did wrong?
Thank you.
sublist v w =
if w == []
then False
else if v == h_w
then True
else if h_w /= []
then sublist v h_w
else sublist v t_w
where
h_w = head w
t_w = tail w
Answer the question
In order to leave comments, you need to log in
isSublist :: Eq a => [a] -> [a] -> Bool
isSublist a b = all (`elem` b) a
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question