Here's my proposal for how to handle dimensionality in Perl 6:

Create a "units" trait that is designed to attach to any Numeric
object.  Dimensional information gets stored as a baggy object - that
is, something that  works just like a Bag, except that the count can
go negative.  (I don't know if the count should be a signed integer or
a Num; what happens in dimensional analysis when you try to take the
square root of two inches?)  Overload the Numeric operators to
properly track the units as well as performing their normal
activities.  Add one or two methods that allow you to easily extract
the raw number and/or the units.

For now, unit conversions are always handled manually, and the units
themselves are completely arbitrary   At some later date we might
consider adding a robust database of units and conversion rates; but
that's a complication that we needn't deal with up front.  Indeed, it
might work best as a module to be included by those who want the added
tools.  Regardless, such a module should not interfere in the ability
to use made-up units on the fly; instead, it should provide additional
details for units that have been properly registered (such as what
kind of value is being measured, which measurement system it's a part
of, what the conversion rates are, and what synonyms exist for it).
The goal should be to enhance, not restrict.

If this is implemented, Duration should be an alias for something to
the effect of "Num but units<second>".  Otherwise, Instant and
Duration remain unchanged.

Thoughts?

-- 
Jonathan "Dataweaver" Lang

Reply via email to