Dimensional analysis with fundeps

Ashley Yakeley ashley@semantic.org
Mon, 9 Apr 2001 14:46:26 -0700


At 2001-04-09 09:36, anatoli wrote:

>4) Allow several unit systems (such as SI and Imperial)
>   to coexist.

That's easy. Just hide the 'Dimensioned' constructor so no-one can see 
what system you're using.

--
type One = Succ Zero
type Mass rep       = Dimensioned One Zero Zero rep
type Length rep     = Dimensioned Zero One Zero rep
type Time rep       = Dimensioned Zero Zero One rep
type Unit rep       = Dimensioned Zero Zero Zero rep

dm x = Dimensioned x

kilogramme = (dm 1) :: (Num rep) => Mass rep
metre  = (dm 1) :: (Num rep) => Length rep
second  = (dm 1) :: (Num rep) => Time rep
unit  = (dm 1) :: (Num rep) => Unit rep

toUnit :: rep -> Dimensioned Zero Zero Zero rep
toUnit = dm

fromUnit :: Dimensioned Zero Zero Zero rep -> rep
fromUnit (dm x) = x
--

...which allows another module to do this...

--
inch = times (toUnit 0.0254) metre

someLength = plus (times (toUnit 5.1) metre) (times (toUnit 3.7) inch)

someLengthInches = fromUnit (divby someLength inch)
--


-- 
Ashley Yakeley, Seattle WA