[Haskell-cafe] Confused about Cyclic struture

Marc A. Ziegert coeus at gmx.de
Thu Jul 7 21:42:10 EDT 2005


well, it is a little bit tricky.
you know, imps do not always make what you want.

 imp_creates x = x `knot` imp x
                 where knot = (:)

imagine the following:
you pull a foulard out of your 	sleeve,

 foulard : sleeve
 where sleeve = imp_creates foulard

and pull

 foulard : foulard : sleeve
 where sleeve = imp_creates foulard

and pull.

 foulard : foulard : foulard : sleeve
 where sleeve = imp_creates foulard

you will waste more and more space, maybe your storage will swell to discworld.
this is recursion, but not a cyclic structure.
on the other hand:

 serviette_ring
 where serviette_ring = foulard `knot` serviette_ring

you will pull one single foulard through that thing.

 x@( foulard `knot` serviette_ring )
 where knot = (:)
       serviette_ring = x

and then there is a knot with the beginnig of the same thing you pulled out before.

 beginning@( foulard `knot` beginning )
 where knot = (:)

if you pull more and more, you will get the same foulard again and again.
you do not need an imp to produce more and more foulards, because this knot closes the ring.
so, you will never fill the room just by pulling, because this is a nice little "cyclic structure".


- marc






More information about the Haskell-Cafe mailing list