3 ms·
There are two ways to get cycles in Haskell. One is through “tying the knot”. E.g. to create an infinite list of 1,1,1,1,1,… ones = 1 : ones This will actual
by wyager 5y ago
There are two ways to get cycles in Haskell.
One is through “tying the knot”. E.g. to create an infinite list of 1,1,1,1,1,…
ones = 1 : ones
This will actually be compiled to a list cell with a pointer back to itself. You can construct more complicated self-referential data structures thanks to laziness.
The other way you could get a cycle is that it actually does have mutable data structures, although their use is restricted so they can’t have any observable mutable effect in pure code. But you have e.g. IORef which is basically a mutable pointer.
If you wanted no cycles you would need to eliminate some subset of laziness, knot-tying transformations, recursion, and any support for mutable data structures. But yes, I think it could be done.