A sample revised prelude for numeric classes
Tom Pledger
Tom.Pledger@peace.com
Mon, 12 Feb 2001 18:18:19 +1300
Brian Boutel writes:
:
| Having Units as types, with the idea of preventing adding Apples to
| Oranges, or Dollars to Roubles, is a venerable idea, but is not in
| widespread use in actual programming languages. Why not?
There was a pointer to some good papers on this in a previous
discussion of units and dimensions:
http://www.mail-archive.com/haskell@haskell.org/msg04490.html
The main complication is that the type system needs to deal with
integer exponents of dimensions, if it's to do the job well.
For example, it should be OK to divide an acceleration (length *
time^-2) by a density (mass * length^-3). Such things may well occur
as subexpressions of something more intuitive, and it's undesirable to
spell out all the anticipated dimension types in a program (a Haskell
98 program, for example) because:
- Only an arbitrary finite number would be covered, and
- The declarations would contain enough un-abstracted clich=E9s to
bring a tear to the eye.
instance Mul Double (Dim_L Double) (Dim_L Double)
instance Mul (Dim_L Double) (Dim_per_T Double) (Dim_L_per_T Dou=
ble)
etc.
Regards,
Tom