non/scala-numerics-refactor — pull request #8 by tixxit (2012-03-10 07:20:35+00:00)
Title: Refactor Real

This is a big refactoring of real. If all went well, nothing has changed functionally. The main difference is that Real is constructed using almost entirely stackable traits. The functionality of Real is split up so that we can mix some of it in selectively (eg. floating point filters, separation bounds, peep-hole optimizations, etc.) and also construct new Real types easily.

The main thing is that Real is now a single class. To handle the AST structure there is a new ADT called Expr[A] and a corresponding typeclass Coexpr[A]. The typeclass lets us map between Expr <-> A. Essentially, if an instance of Coexpr[A] exists, it means that A has a structure that can be modelled by Expr. This gives us immediate access to extractors and constructors (Add, Sub, IntLit, etc.).

Also, you can use someReal.toTreeString to get a nice ASCII art version of the real numbers underlying expression tree.