检查第一个参数中的所有元素是否出现在第二个参数中

问题描述 投票:-1回答:1

我从我的代码中得到了错误的结果。

我想检查第一个参数列表中的元素是否出现在第二个参数列表中,并且我使用了此停顿Check, if list is a sublist of another list中的代码,但没有得到想要的结果。

del :: Eq t => [t] -> [t] -> Bool
del [] [] = True 
del _ []  = False 
del [] _  = True
del (x:xs) (y:ys)
    | x == y    = del xs ys
    | otherwise = del (x:xs) ys

del [2,3] [3,3,1]应该返回False,但确实如此。del“ cbbbc”“ bca”应该返回True,但是返回False,我不明白为什么。

我从我的代码中得到了错误的结果。我想检查第一个参数列表中的元素是否出现在第二个参数列表中,并且如果该列表是...

haskell
1个回答
0
投票

您即将移除y;仅仅因为x /= y并不意味着x == z对于z中的其他某些值ys都不成立。如果您不需要在all

© www.soinside.com 2019 - 2024. All rights reserved.