Set, Map libraries

Jens Fisseler jens.fisseler at fernuni-hagen.de
Thu Jun 2 04:00:19 EDT 2005


> 1.  elems     :: Set a -> [a]
>     setToList :: Set a -> [a]
> 
>   These two look like synonyms, but have different comments.
>   Am I missing something? 

Both functions compute the same list, and IMHO the comments state the
same.

> 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?

No, 'genericSize' cannot work in O(1) time, but by looking at the source
you will see that a 'Set' contains an element representing its size, so
'size' can work in constant time.

Regards,

	Jens


More information about the Glasgow-haskell-users mailing list