Jon Lang asked me if I intended to send this message to him privately.
 The answer is "No"...


---------- Forwarded message ----------
From: Buddha Buck <blaisepas...@gmail.com>
Date: Thu, Nov 18, 2010 at 10:39 PM
Subject: Re: dimensionality in Perl 6
To: Jon Lang <datawea...@gmail.com>


On Thu, Nov 18, 2010 at 7:58 PM, Jon Lang <datawea...@gmail.com> wrote:
> 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.

An added complication is "dimensionality".  ergs, joules, btu and eV
are all units of energy, and it isn't unreasonable to want to add or
subtract energies of different units (my house used (100 therm +
8000kWh) of energy last month, for example).  However, it is incorrect
to add ergs and Newtons, since they are of different dimensionality.

The more robust units/dimensional analysis packages I've seen might
not allow one to add therms and kWh, but they do know that therms and
kWh are both [ML^2/T^2],  I believe at the time I was looking at
JScience's work on JSR-275.  In this setup, when units are registered,
they are given a dimensionality (essentially, a "baggy" of
dimensions), and values are given a "baggy" of units (and thus an
implicit "baggy" of dimensions, the union of the dimensions of the
units).

I don't think a Num is necessary, but I could see a Rat.

> 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