[project @ 2005-01-19 17:20:31 by ross]
[ghc-base.git] / Data / Set.hs
index e515667..8376f25 100644 (file)
@@ -1,33 +1,37 @@
-{-| Module      :  Data.Set
-    Copyright   :  (c) Daan Leijen 2002
-    License     :  BSD-style
-    Maintainer  :  libraries@haskell.org
-    Stability   :  provisional
-    Portability :  portable
-
-  An efficient implementation of sets. 
-
-  This module is intended to be imported @qualified@, to avoid name
-  clashes with Prelude functions.  eg.
-
-  >  import Data.Set as Set
-
-  The implementation of "Set" is based on /size balanced/ binary trees (or
-  trees of /bounded balance/) as described by:
-
-     * Stephen Adams, \"/Efficient sets: a balancing act/\", Journal of Functional
-       Programming 3(4):553-562, October 1993, <http://www.swiss.ai.mit.edu/~adams/BB>.
-
-     * J. Nievergelt and E.M. Reingold, \"/Binary search trees of bounded balance/\",
-       SIAM journal of computing 2(1), March 1973.
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Data.Set
+-- Copyright   :  (c) Daan Leijen 2002
+-- License     :  BSD-style
+-- Maintainer  :  libraries@haskell.org
+-- Stability   :  provisional
+-- Portability :  portable
+--
+-- An efficient implementation of sets.
+--
+-- This module is intended to be imported @qualified@, to avoid name
+-- clashes with "Prelude" functions.  eg.
+--
+-- >  import Data.Set as Set
+--
+-- The implementation of 'Set' is based on /size balanced/ binary trees (or
+-- trees of /bounded balance/) as described by:
+--
+--    * Stephen Adams, \"/Efficient sets: a balancing act/\",
+--     Journal of Functional Programming 3(4):553-562, October 1993,
+--     <http://www.swiss.ai.mit.edu/~adams/BB>.
+--
+--    * J. Nievergelt and E.M. Reingold,
+--     \"/Binary search trees of bounded balance/\",
+--     SIAM journal of computing 2(1), March 1973.
+--
+-- Note that the implementation is /left-biased/ -- the elements of a
+-- first argument are always perferred to the second, for example in
+-- 'union' or 'insert'.  Of course, left-biasing can only be observed
+-- when equality is an equivalence relation instead of structural
+-- equality.
+-----------------------------------------------------------------------------
 
-  Note that the implementation is /left-biased/ -- the elements of a
-  first argument are always perferred to the second, for example in
-  'union' or 'insert'.  Of course, left-biasing can only be observed
-  when equality an equivalence relation instead of structural
-  equality.
--}
----------------------------------------------------------------------------------
 module Data.Set  ( 
             -- * Set type
               Set          -- instance Eq,Show
@@ -110,6 +114,7 @@ module Data.Set  (
 import Prelude hiding (filter,foldr,foldl,null,map)
 import Data.Monoid
 import qualified Data.List as List
+import Data.Typeable
 
 {-
 -- just for testing
@@ -504,6 +509,13 @@ showSet (x:xs)
     
 
 {--------------------------------------------------------------------
+  Typeable/Data
+--------------------------------------------------------------------}
+
+#include "Typeable.h"
+INSTANCE_TYPEABLE1(Set,setTc,"Set")
+
+{--------------------------------------------------------------------
   Utility functions that return sub-ranges of the original
   tree. Some functions take a comparison function as argument to
   allow comparisons against infinite values. A function [cmplo x]
@@ -1077,53 +1089,66 @@ prop_List xs
 --------------------------------------------------------------------}
 
 {-# DEPRECATED emptySet "Use empty instead" #-}
+-- | Obsolete equivalent of 'empty'.
 emptySet :: Set a
 emptySet = empty
 
-{-# DEPRECATED mkSet "Equivalent to 'foldl insert empty'." #-}
+{-# DEPRECATED mkSet "Use fromList instead" #-}
+-- | Obsolete equivalent of 'fromList'.
 mkSet :: Ord a => [a]  -> Set a
-mkSet = List.foldl' (flip insert) empty
+mkSet = fromList
 
-{-# DEPRECATED setToList "Use instead." #-}
+{-# DEPRECATED setToList "Use elems instead." #-}
+-- | Obsolete equivalent of 'elems'.
 setToList :: Set a -> [a] 
 setToList = elems
 
 {-# DEPRECATED unitSet "Use singleton instead." #-}
+-- | Obsolete equivalent of 'singleton'.
 unitSet :: a -> Set a
 unitSet = singleton
 
 {-# DEPRECATED elementOf "Use member instead." #-}
+-- | Obsolete equivalent of 'member'.
 elementOf :: Ord a => a -> Set a -> Bool
 elementOf = member
 
 {-# DEPRECATED isEmptySet "Use null instead." #-}
+-- | Obsolete equivalent of 'null'.
 isEmptySet :: Set a -> Bool
 isEmptySet = null
 
 {-# DEPRECATED cardinality "Use size instead." #-}
+-- | Obsolete equivalent of 'size'.
 cardinality :: Set a -> Int
 cardinality = size
 
 {-# DEPRECATED unionManySets "Use unions instead." #-}
+-- | Obsolete equivalent of 'unions'.
 unionManySets :: Ord a => [Set a] -> Set a
 unionManySets = unions
 
 {-# DEPRECATED minusSet "Use difference instead." #-}
+-- | Obsolete equivalent of 'difference'.
 minusSet :: Ord a => Set a -> Set a -> Set a
 minusSet = difference
 
 {-# DEPRECATED mapSet "Use map instead." #-}
+-- | Obsolete equivalent of 'map'.
 mapSet :: (Ord a, Ord b) => (b -> a) -> Set b -> Set a
 mapSet = map
 
 {-# DEPRECATED intersect "Use intersection instead." #-}
+-- | Obsolete equivalent of 'intersection'.
 intersect :: Ord a => Set a -> Set a -> Set a
 intersect = intersection
 
-{-# DEPRECATED addToSet "Use insert instead." #-}
+{-# DEPRECATED addToSet "Use 'flip insert' instead." #-}
+-- | Obsolete equivalent of @'flip' 'insert'@.
 addToSet :: Ord a => Set a -> a -> Set a
 addToSet = flip insert
 
-{-# DEPRECATED delFromSet "Use delete instead." #-}
+{-# DEPRECATED delFromSet "Use `flip delete' instead." #-}
+-- | Obsolete equivalent of @'flip' 'delete'@.
 delFromSet :: Ord a => Set a -> a -> Set a
 delFromSet = flip delete