External Publication
Visit Post

Minimal processing of continued fractions

Haskell Community [Unofficial] February 15, 2026
Source
This formulation also made me wonder whether there’s an opportunity to encode productivity at the type/structure level rather than relying on the y0 == y1 check alone. For example, you could imagine splitting the state machine into two explicit phases: * Accumulate: consume CF terms until the matrix is “stable enough.” * Emit: guaranteed to produce at least one digit before needing more input In other words, make it emit totally once entered, so the only partiality lives in the transition between phases. That might let you model the whole thing as something like a Mealy machine or even a Stream transformer, where non-productivity becomes structurally impossible rather than a runtime condition. It feels like continued fractions are crying out for that kind of “digit-safe” invariant, similar to how digit-by-digit algorithms for √2 or π enforce progress by construction. I don’t know if it simplifies the code, but it might make the reasoning story even cleaner. Either way, this fold-inside-unfold pattern is a great lens - it’s much clearer than the recursive versions I was circling around before.

Discussion in the ATmosphere

Loading comments...