Re: Map, Set libraries

2005-06-02 Thread Christian Maeder
Serge D. Mechveliani wrote:
> As Jens Fisseler notes, I have made a confusion about
> 
> Set.elems, Set.toList, Set.setToList.

There is even Set.toAscList (although one may argue that should be
Set.toDistinctAscList)

I think the right choice is Set.toList (replacing setToList)

Is Set.elems just a (nicer?, useless?) synonym for Set.toList?
There are also Map.assocs and Map.toList being synonyms.

But Map.elems is different from Map.toList and Set.elems would only
correspond to Map.elems for some identity maps (not for the old set
implementation using maps with dummy elements "()")

Cheers Christian

P.S Map.insert indeed replaces existing values (and should be used
instead of addToFM with changed argument position for the input map)
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: Map, Set libraries

2005-06-02 Thread Serge D. Mechveliani
As Jens Fisseler notes, I have made a confusion about

Set.elems, Set.toList, Set.setToList.

Docs on   setToList  occurs all right (`Obsolete' item).
And for some reason,  Data.Set.html  shows the pair
> > "
> >   elems :: Set a -> [a]
> >   O(n). The elements of a set.
> > 
> >   toList :: Set a -> [a]
> >   O(n). Convert the set to a list elements.
> > "

Hm, let it be.
I do not know, maybe the documentation could say why there are 
two of them.

-
Serge Mechveliani
[EMAIL PROTECTED]

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: Map, Set libraries

2005-06-02 Thread Jens Fisseler
> I meant the description in the ghc-6.4 documentation.
> Data.Set.html  says
> "
>   elems :: Set a -> [a]
>   O(n). The elements of a set.
> 
>   setToList :: Set a -> [a]
>   O(n). Convert the set to a list elements.
> "
> What is the difference? 
> If they are really equivalent, then, it is natural either to
> remove `elems' or to follow the general GHC policy and to move 
> setToList  to the `Obsolete' list section in documentation, like
> it was done with many other functions for Set and FiniteMap.
> - ?

Well, seems like both of us have messed something up. The ghc-6.4
documentation for 'setToList' says "Obsolete equivalent of elems",
whereas the documentation for 'toList' (that what I was referring to)
says "O(n). Convert the set to a list of elements."

But, by looking at the source code, one can easily see that 'setToList'
if defined in terms of 'elems'

setToList :: Set a -> [a] 
setToList = elems

which in turn is defined as

elems :: Set a -> [a]
elems s
  = toList s

So, both 'setToList' and 'elems' do the same, and 'setToList' is marked as 
obsolete, so use 'elems'.

Regards,

Jens
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users