I'm new to Haskell and doing some simple exercises. For this exercise I'm writing a function that checks whether one list is a subset of another list using recursion.
Here's the code:
subset [] xs = True
subset (x:xs) ys = if elem x ys == False then False
else subset (tail xs) (delete x ys)
I'm getting the following error message:
C:\Functioneel programmeren\week4.hs:9:43: error:
Variable not in scope: delete :: t1 -> t t1 -> t t1
What does this even mean?
This program only works when I change "(delete x ys)" to "ys", but then it doesn't do what it's supposed to do.
Any help would be great, thanks in advance.
delete
needs to be imported. According to https://www.haskell.org/hoogle/?hoogle=delete , you should add import Data.List
to the beginning.
Besides, I guess your function subset
is wrong. The result of subset [1, 2, 1] [1, 2, 3]
is False
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.