[Haskell-beginners] How to convert a Data.Set to a Descending List?

Alexander Batischev eual.jp at gmail.com
Sun Aug 21 10:53:57 CEST 2011


Hi!

On Sun, Aug 21, 2011 at 01:48:05PM +0530, Sunil S Nandihalli wrote:
>  Is there a more efficient way to convert a Set to a descending list?
> I was looking for a function similar to Set.toAscList something like
> Set.toDecList . I feel first converting to a ascending list and then
> reversing may be in-efficient given that I actually don't need all the
> elements only a last couple of elements..

Why don't you use something like

  take N $ Set.toAscList s

then? "A last couple of elements" in descending list would be "a first
couple of elements" in ascending list. That approach may even be
*faster* than building descending list, because to get your elements
you'll build only beginning of the list, while with descending list,
you'll need to build whole list in order to get last elements.

-- 
Regards,
Alexander Batischev

1024D/69093C81
F870 A381 B5F5 D2A1 1B35  4D63 A1A7 1C77 6909 3C81
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110821/2b3b44af/attachment.pgp>


More information about the Beginners mailing list