[Haskell-cafe] recursion problem part 2

Jerzy Karczmarczuk jerzy.karczmarczuk at unicaen.fr
Sat Feb 7 02:15:37 UTC 2015

Le 07/02/2015 02:48, Jeffrey Brown a écrit :
> I see: what matters is that ++ has to traverse to the end of the first 
> list. The order in which its two arguments are evaluated is irrelevant.
> Thank you, David and Arjun!
> On Fri, Feb 6, 2015 at 5:38 PM, Arjun Comar <nrujac at gmail.com 
> <mailto:nrujac at gmail.com>> wrote:
>     Jeff,
>     An expression of the form xs ++ [x] appends the element to the end
>     of the list. In order to evaluate the result, the ++ function
>     iterates through the elements of the first list to find the end of
>     the list then sets the tail of the last element of the first list
>     to the second list.
Gentlemen, don't forget that Haskell is lazy, and this traversal takes 
place only when the list is effectively traversed by a consumer, which 
stores everything (and doesn't get rid of elements read). This might be 
the case here if somebody wants to keep and use the "digit 
representation" of a number, but please do not consider this phenomenon 
as inherent to the list creation algorithm.

Jerzy Karczmarczuk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20150207/0737e3a4/attachment.html>

More information about the Haskell-Cafe mailing list