Continued fraction/Arithmetic/Construct from rational number: Difference between revisions

Content added Content deleted
Line 641: Line 641:
This example solution was written specifically with the idea of providing a general representation of possibly infinitely long continued fractions. Terms can be obtained arbitrarily, by their indices. One obtains '''Some term''' if the term is finite, or '''None()''' if the term is infinite.
This example solution was written specifically with the idea of providing a general representation of possibly infinitely long continued fractions. Terms can be obtained arbitrarily, by their indices. One obtains '''Some term''' if the term is finite, or '''None()''' if the term is infinite.


One drawback is that, because a continued fraction is memoized, it may need to be updated. Therefore it must be stored in a mutable location, such as a '''var'''.
One drawback is that, because a continued fraction is memoized, and its terms are generated as needed, the data structure may need to be updated. Therefore it must be stored in a mutable location, such as a '''var'''.


<syntaxhighlight lang="ats">(*------------------------------------------------------------------*)
<syntaxhighlight lang="ats">(*------------------------------------------------------------------*)