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

Sunil S Nandihalli sunil.nandihalli at gmail.com
Sun Aug 21 11:04:15 CEST 2011


Hi Alex,
 Sorry for the miswording of my question. The think I am interested in
the first couple in the descending list (which would be last few in
the ascending list)

Thanks
Sunil.

On Sun, Aug 21, 2011 at 2:23 PM, Alexander Batischev <eual.jp at gmail.com> wrote:
> 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
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
>
> iEYEARECAAYFAk5Qx6UACgkQoaccd2kJPIHfpwCfVhaOZJnfxA3wJVW6EImZX5EE
> 7Q4AnAu8oUiFTnek0lkBdq7HJLHREZsg
> =LXPG
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>



More information about the Beginners mailing list