[Haskell-beginners] Appending to a list
Adrian Neumann
aneumann at inf.fu-berlin.de
Sun Feb 8 03:26:41 EST 2009
Yes, appending to the tail of a list is an expensive operation.
You may ask yourself why there is no pointer to the end of a list.
That's because the end is in general not known (e.g. if the list is
produced by a computation, or if it's infinite).
However if you know up front that your list will be finite and you
don't rely on lazyness you may want to use a Data.Sequence instead
> http://www.haskell.org/ghc/docs/latest/html/libraries/containers/
Data-Sequence.html
Cheers,
Adrian
Am 07.02.2009 um 21:29 schrieb Francesco Bochicchio:
> Hi all,
>
> in my haskell exercises I often build list by appending values at
> the end.
> But I read somewhere that in haskell this is inefficient since
> there is no
> 'pointer to the tail of the list'. I've also seen some example of
> recursive
> functions which build the list tail-first and then in the base case
> of the
> recursion returns the reverse of the accumulated results, counting
> on the fact
> that in haskell 'reverse list' just means 'consume the list from
> the tail'.
>
> Just out of curiosity (I have no need to speed up my little
> programs with which I try to teach myself
> some haskell): is this a consolidated pattern? And are append
> really expensive?
>
> Ciao
> -------
> FB
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 194 bytes
Desc: Signierter Teil der Nachricht
Url : http://www.haskell.org/pipermail/beginners/attachments/20090208/0e9cb17f/PGP.bin
More information about the Beginners
mailing list