Set, Map libraries

Serge D. Mechveliani mechvel at
Wed Jun 1 10:20:35 EDT 2005

Dear GHC team,

I am looking into the .html docs on the libraries of  Map and Set.
Here follow the questions and notices.

1.  elems     :: Set a -> [a]
    setToList :: Set a -> [a]

  These two look like synonyms, but have different comments.
  Am I missing something? 

2.  size :: Set a -> Int    -- O(1) ...

  And for large sets, the user needs to program

  genericSize :: Set a -> Integer  
  genericSize =  genericLength . Data.Set.elems
  Is this possible to make it O(1) too?

3. Data.Map  has  lookup  and  findWithDefault.
   According to name correspondence, a natural name for the latter
   would be  lookupWithDefault
   - ?

4. Data.Set.intersection.
   In old library, it was  `intersect'  -- if I recall correct.
   So, it is natural to include `intersect' to the `Obsolete' list. 

5. Name resolution.

    Ambiguous occurrence `null'
    It could refer to either `Data.Set.null', imported from Data.Set at
   or `GHC.List.null', imported from Prelude at ./Prelude0

  Could the compiler detect where  null  applies to list
  and where to  Set ? 
  For this is visible from the types in the user program.

6. My module applies  Data.Set.null (s :: Set a),
   and                         null (xs :: [a]).

  Why ghc reports of the clash with  GHC.List.null ?
  Is  GHC.List  same as old  List  library module?
  Should I write
                 import GHC.List (genericLength, null)
  instead of     import List     (genericLength)

With kind regards,

Serge Mechveliani
mechvel at

More information about the Glasgow-haskell-users mailing list