haskell中是否有一个函数来判断一个列表中的每个元素是否在另一个列表中?

Is there a function in haskell to determine if each element in a list is in another list?

我想知道 haskell 中是否有一个函数可以确定列表中的每个元素是否在另一个列表中。我写了我自己的,但它看起来像是 PreludeData.List

中的东西
each :: Eq a => [a] -> [a] -> Bool
each xs ys = foldl (\acc x -> if x `elem` ys then True && acc else False) True xs

是否已经存在这样的东西?

您特别想要的集合操作不在 Prelude 中,但 all 使定义有些微不足道(尽管不一定有效)。

-- Check if every element in xs is in ys (i.e., is xs a subset of ys)
each xs ys = all (`elem` ys) xs

假设您的列表没有重复值,您可以尝试 (\)

import Data.List

-- Check if removing all elements in ys from xs produces an empty list.
each xs ys = null (xs \ ys)