CC: Functional dependencies question
Ashley Yakeley
ashley@semantic.org
Wed, 21 May 2003 00:53:37 -0700
In article <200305130355.h4D3ttcB013484@adric.fnmoc.navy.mil>,
oleg@pobox.com wrote:
> Just for the record: yet another way to introduce negative numbers is
> through an explicit constructor Neg. For example:
> http://pobox.com/~oleg/ftp/Computation/type-arithmetics.html
> (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.
<http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/hbase/Source/HBase/TypeCa
lc/>.
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
import PhysicalUnits
-- 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