[Haskell-beginners] Circular Linked Lists
byorgey at seas.upenn.edu
Tue Feb 3 09:17:12 EST 2009
> cycle doesn't actually construct in memory a cyclic data structure, as one
> might in C. It's more like those repeat bars in sheet music.
cycle xs = xs' where xs' = xs ++ xs'
That sure looks like a cyclic data structure to me! xs' references a
thunk which computes (xs ++ xs'); this thunk, in turn, references
xs'. cycle is memory-efficient precisely because it *does* actually
construct a cyclic data structure.
More information about the Beginners