Remove Control.Parallel*, now in package parallel
[haskell-directory.git] / Data / Set.hs
index fd80ca6..04d0100 100644 (file)
@@ -9,10 +9,11 @@
 --
 -- An efficient implementation of sets.
 --
--- This module is intended to be imported @qualified@, to avoid name
--- clashes with "Prelude" functions.  eg.
+-- Since many function names (but not the type name) clash with
+-- "Prelude" names, this module is usually imported @qualified@, e.g.
 --
--- >  import Data.Set as Set
+-- >  import Data.Set (Set)
+-- >  import qualified Data.Set as Set
 --
 -- The implementation of 'Set' is based on /size balanced/ binary trees (or
 -- trees of /bounded balance/) as described by:
@@ -339,7 +340,16 @@ hedgeDiff cmplo cmphi t (Bin _ x l r)
   Intersection
 --------------------------------------------------------------------}
 -- | /O(n+m)/. The intersection of two sets.
--- Elements of the result come from the first set.
+-- Elements of the result come from the first set, so for example
+--
+-- > import qualified Data.Set as S
+-- > data AB = A | B deriving Show
+-- > instance Ord AB where compare _ _ = EQ
+-- > instance Eq AB where _ == _ = True
+-- > main = print (S.singleton A `S.intersection` S.singleton B,
+-- >               S.singleton B `S.intersection` S.singleton A)
+--
+-- prints @(fromList [A],fromList [B])@.
 intersection :: Ord a => Set a -> Set a -> Set a
 intersection Tip t = Tip
 intersection t Tip = Tip
@@ -745,18 +755,15 @@ deleteFindMax t
 
 -- | /O(log n)/. Retrieves the minimal key of the set, and the set stripped from that element
 -- @fail@s (in the monad) when passed an empty set.
-minView :: Monad m => Set a -> m (Set a, a)
+minView :: Monad m => Set a -> m (a, Set a)
 minView Tip = fail "Set.minView: empty set"
-minView x = return (swap $ deleteFindMin x)
+minView x = return (deleteFindMin x)
 
 -- | /O(log n)/. Retrieves the maximal key of the set, and the set stripped from that element
 -- @fail@s (in the monad) when passed an empty set.
-maxView :: Monad m => Set a -> m (Set a, a)
+maxView :: Monad m => Set a -> m (a, Set a)
 maxView Tip = fail "Set.maxView: empty set"
-maxView x = return (swap $ deleteFindMax x)
-
-swap (a,b) = (b,a)
-
+maxView x = return (deleteFindMax x)
 
 
 {--------------------------------------------------------------------