Is there in the Standard Prelude functions which implement the union and the intersection of sets ?
union :: (Eq a) => [a] -> [a] -> [a]
inters
There are union and intersect functions on lists in the standard libraries, located in Data.List
but not in the Prelude
itself.
As far as efficiency goes, I'm going to say "no" to all of the above, both yours and the standard library's. There's really no way either can ever be efficient operations on a list with only an Eq
constraint. That said, you may still find the implementation in Data.List
informative--see the links above, which I've pointed directly to the relevant source.
Edit -- As a brief addendum for the sake of posterity, be sure to see Don's answer for what you actually want to use for this purpose, rather than the narrower question of "do these functions exist at all".
The base library provides list versions, as camccann points out. If you want something a bit more efficient, consider Data.Set, which provides:
union :: Ord a => Set a -> Set a -> Set a
intersection :: Ord a => Set a -> Set a -> Set a
with complexity O(n+m).