3 ms·
One of the main problems in programming is, that a self-referential structure may be cyclic and a cyclic structure combined with eager evaluation leads to a inf
by maweki 2y ago
One of the main problems in programming is, that a self-referential structure may be cyclic and a cyclic structure combined with eager evaluation leads to a infinitely looping program.
As Haskell is lazy, this self-referencing is quite nice. There is this reddit-joke about implementing an is-even function. In haskell we can write an infinite list of alternating True/False like `alt = True : False : alt` and is-even is now `is_even n = alt !! n` where !! is array access.
Even if the data structure is not cyclic, but you're talking about sharing, then you have to have syntax about explicit sharing and the lifetime of the share (immutability comes to the rescue again), as detecting sharing is a very difficult problem in and of itself.