2009-12-29

modular coercion

11.9: adda/oop/modular coercion

. one way for superclasses like number to facilitate modularity
is to provide a common intermediate type (cit):
eg, number.class can describe record variants for all of its subtypes:
complex.rectangular.coord's =
( co#real.real
, co.imaginary.real
)
complex.polar.coord's = ()
real = { quotient, float.symbol, }
quotient = ( dividend.int, divisor.int )
int = {0,1, ... }
float = {0, 1/inf, 1/(inf-1), ...., 1, 1+1/inf, ... inf }
float.symbol = { pi, e, ... },
.. the supertype's cit is giving the ways to describe value literals
in terms of lists, symbols, and integers .
. then subtypes can implement binary versions of these symbolic literals
in any way they choose .
. this way they don't need to know each other's impl'details
in order to supply conversions between subtypes;
they simply convert their subtype to or from the symbolic value
-- it's not the quickest,
but it's definitely an improvement over char'string conversions
if modularity between subtypes is required .
]

No comments:

Post a Comment