CC: Functional dependencies question
Wed, 21 May 2003 00:53:37 -0700
In article <200305130355.h4D3ttcB013484@adric.fnmoc.navy.mil>,
> Just for the record: yet another way to introduce negative numbers is
> through an explicit constructor Neg. For example:
> (sorry, the code uses C++ templates. The idea is just the same
> however: a mere Prolog in a more verbose notation). The above example
> demonstrates division of signed Peano numbers. The Neg constructor
> becomes quite handy then.
I prefer NegativeSucc, i.e. -(n+1) or -n-1. My integer types are thus T
or NegativeSucc T for any natural type T, and the two don't overlap.
Another trick is to use the same class for addition and subtraction:
class Add a b ab | a b -> ab, ab a -> b;
I found you can't build the instances if you have all three possible
fundeps (because of overlaps), but you can with two.
As for dimensions, what would be most interesting would be to allow the
user to add their own "basis" units, so for instance:
module MyModule where
-- new basis unit
type Cost = [whatever]
dollar :: Cost
dollar = [whatever]
goldValue :: (Div Mass Cost t) => t
goldValue = ...
...but that may be hard and/or messy.
Ashley Yakeley, Seattle WA