[Haskell-beginners] Circular Linked Lists

Brent Yorgey 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.

It doesn't?

  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.

-Brent


More information about the Beginners mailing list