is there union and intersect Haskell Prelude implementation?

后端 未结 2 1924
终归单人心
终归单人心 2020-12-20 14:43

Is there in the Standard Prelude functions which implement the union and the intersection of sets ?

union      :: (Eq a) => [a] -> [a] -> [a]
inters         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-20 15:00

    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).

提交回复
热议问题