Commits

Thijs Alkemade committed 3016df0

A lot of extra SI and SI-derived units.

Comments (0)

Files changed (3)

src/UnitTyped/SI.hs

 	showunit _ _ = "K"
 
 ----
+-- Current
+----
+
+data Current
+type CurrentUnit = UnitCons Current (Pos One) UnitNil
+
+data Ampere
+type Amperes = (Fractional f) => Value f CurrentUnit Ampere
+
+instance Convertable CurrentUnit Ampere where
+	factor _ = 1
+	showunit _ _ = "A"
+
+----
+-- Luminous
+----
+
+data Luminous
+type LuminousUnit = UnitCons Luminous (Pos One) UnitNil
+
+data Candela
+type Candelas = (Fractional f) => Value f LuminousUnit Candela
+
+instance Convertable LuminousUnit Candela where
+	factor _ = 1
+	showunit _ _ = "cd"
+
+----
 
 count :: (Fractional f) => Value f CountUnit Count
 count = one
 --
 
 kelvin :: (Fractional f) => Value f TemperatureUnit Kelvin
-kelvin = one
+kelvin = one
+
+--
+
+ampere :: (Fractional f) => Value f CurrentUnit Ampere
+ampere = one
+
+--
+
+candela :: (Fractional f) => Value f LuminousUnit Candela
+candela = one

src/UnitTyped/SI/Derived.hs

 import UnitTyped.SI
 import UnitTyped.SI.Meta
 
-import qualified Prelude
-import Prelude (Show(..), Fractional, ($), (++), Double, const, Bool(..), otherwise, undefined, String(..))
+import Data.Ratio
 
 ---
 -- Count
 ---
 
 data Percentage
-type Percentages = (Fractional f) => Value f LengthUnit Mile
+type Percentages = (Fractional f) => Value f CountUnit Percentage
 
 instance Convertable CountUnit Percentage where
 	factor _ = 0.01
 	showunit _ _ = "%"
 
+data Permil
+type Permils = (Fractional f) => Value f CountUnit Permil
+
+instance Convertable CountUnit Permil where
+	factor _ = 0.001
+	showunit _ _ = "‰"
+
+data Ppm
+type Ppms = (Fractional f) => Value f CountUnit Ppm
+
+instance Convertable CountUnit Ppm where
+	factor _ = 0.1^6
+	showunit _ _ = "ppm"
+
+data Ppb
+type Ppbs = (Fractional f) => Value f CountUnit Ppb
+
+instance Convertable CountUnit Ppb where
+	factor _ = 0.1^9
+	showunit _ _ = "ppb"
+
+data Ppt
+type Ppts = (Fractional f) => Value f CountUnit Ppt
+
+instance Convertable CountUnit Ppt where
+	factor _ = 0.1^12
+	showunit _ _ = "ppt"
+
+data Radian
+type Radians = (Fractional f) => Value f CountUnit Radian
+
+instance Convertable CountUnit Radian where
+	factor _ = 1
+	showunit _ _ = "rad"
+
+data Degree
+type Degrees = (Fractional f) => Value f CountUnit Degree
+
+instance Convertable CountUnit Degree where
+	factor _ = 180 / 3.141592653589793
+	showunit _ _ = "°"
+
 ----
 -- Length
 ----
 	factor _ = 86400
 	showunit _ _ = "day"
 
+data Year
+type Years = (Fractional f) => Value f TimeUnit Year
+
+instance Convertable TimeUnit Year where
+	factor _ = 365.2425 * 24 * 60 * 60
+	showunit _ _ = "yr"
+
+data JulianYear
+type JulianYears = (Fractional f) => Value f TimeUnit JulianYear
+
+instance Convertable TimeUnit JulianYear where
+	factor _ = 31557600
+	showunit _ _ = "a"
+
 --
 
 data Herz
 	factor _ = 1
 	showunit _ _ = "Pa"
 
+type Charge = (UnitCons Time (Pos One) (UnitCons Current (Pos One) UnitNil))
+data Coulomb
+
+instance Convertable Charge Coulomb where
+	factor _ = 1
+	showunit _ _ = "C"
+
+type Potential = (UnitCons Current (Neg One) (UnitCons Mass (Pos One) (UnitCons Length (Pos (Suc One)) (UnitCons Time (Neg (Suc (Suc One))) UnitNil))))
+data Volt
+type Volts = (Fractional f) => Value f Potential Volt
+
+instance Convertable Potential Volt where
+	factor _ = 1
+	showunit _ _ = "V"
+
+type Capacitance = (UnitCons Current (Pos (Suc One)) (UnitCons Mass (Neg One) (UnitCons Length (Neg (Suc One)) (UnitCons Time (Pos (Suc (Suc (Suc One)))) UnitNil))))
+data Farad
+type Farads = (Fractional f) => Value f Capacitance Farad
+
+instance Convertable Capacitance Farad where
+	factor _ = 1
+	showunit _ _ = "F"
+
+type Resistance = (UnitCons Current (Neg (Suc One)) (UnitCons Time (Neg (Suc (Suc One))) (UnitCons Length (Pos (Suc One)) (UnitCons Mass (Pos One) UnitNil))))
+data Ohm
+type Ohms = (Fractional f) => Value f Resistance Ohm
+
+instance Convertable Resistance Ohm where
+	factor _ = 1
+	showunit _ _ = "Ω"
+
+type Conductance = (UnitCons Current (Pos (Suc One)) (UnitCons Mass (Neg One) (UnitCons Length (Neg (Suc One)) (UnitCons Time (Pos (Suc (Suc One))) UnitNil))))
+data Siemens
+
+instance Convertable Conductance Siemens where
+	factor _ = 1
+	showunit _ _ = "S"
+
+type Flux = (UnitCons Current (Neg One) (UnitCons Length (Pos (Suc One)) (UnitCons Mass (Pos One) (UnitCons Time (Neg (Suc One)) UnitNil))))
+data Weber
+
+instance Convertable Flux Weber where
+	factor _ = 1
+	showunit _ _ = "Wb"
+
+type FluxDensity = (UnitCons Length (Neg One) (UnitCons Time (Neg (Suc One)) (UnitCons Mass (Pos One) (UnitCons Current (Neg One) UnitNil))))
+data Tesla
+
+instance Convertable FluxDensity Tesla where
+	factor _ = 1
+	showunit _ _ = "T"
+
+type Inductance = (UnitCons Current (Neg (Suc One)) (UnitCons Time (Neg (Suc One)) (UnitCons Mass (Pos One) (UnitCons Length (Pos (Suc One)) UnitNil))))
+data Henry
+
+instance Convertable Inductance Henry where
+	factor _ = 1
+	showunit _ _ = "H"
+
 --
 
 percentage :: (Fractional f) => Value f CountUnit Percentage
 percentage = one
 
+permil :: (Fractional f) => Value f CountUnit Permil
+permil = one
+
+ppm :: (Fractional f) => Value f CountUnit Ppm
+ppm = one
+
+ppb :: (Fractional f) => Value f CountUnit Ppb
+ppb = one
+
+ppt :: (Fractional f) => Value f CountUnit Ppt
+ppt = one
+
+rad :: (Fractional f) => Value f CountUnit Radian
+rad = one
+
+deg :: (Fractional f) => Value f CountUnit Degree
+deg = one
+
 --
 
 kilometer = kilo meter
 day :: (Fractional f) => Value f TimeUnit Day
 day = one
 
+year :: (Fractional f) => Value f TimeUnit Year
+year = one
+
+julianyear :: (Fractional f) => Value f TimeUnit JulianYear
+julianyear = one
+
 herz :: (Fractional f) => Value f (UnitCons Time (Neg One) UnitNil) Herz
 herz = one
 
 watt = one
 
 pascal :: (Fractional f) => Value f Pressure Pascal
-pascal = one
+pascal = one
+
+coulomb :: (Fractional f) => Value f Charge Coulomb
+coulomb = one
+
+volt :: (Fractional f) => Value f Potential Volt
+volt = one
+
+farad :: (Fractional f) => Value f Capacitance Farad
+farad = one
+
+ohm :: (Fractional f) => Value f Resistance Ohm
+ohm = one
+
+siemens :: (Fractional f) => Value f Conductance Siemens
+siemens = one
+
+weber :: (Fractional f) => Value f Flux Weber
+weber = one
+
+tesla :: (Fractional f) => Value f FluxDensity Tesla
+tesla = one
+
+henry :: (Fractional f) => Value f Inductance Henry
+henry = one

src/UnitTyped/SI/Meta.hs

 import UnitTyped.SI
 import UnitTyped
 
-import qualified Prelude
-import Prelude (Show(..), Fractional, ($), (++), Double, const, Bool(..), otherwise, undefined, String(..))
-
 ----
 -- Meta-units
 ----
 	               sub = one
 	               self :: (Fractional f) => Value f a (m b)
 	               self = one
-	           in (Prelude.*) (metafactor self) (factor sub)
+	           in (metafactor self) * (factor sub)
 	showunit b v = let
 			 		   u :: (Fractional f) => Value f a b
 					   u = one
 data Hecto a
 
 instance (Convertable a b) => MetaUnit Hecto a b where
-	metafactor _ = 100
+	metafactor _ = 10^2
 	metashow _ = "h"
 
 data Kilo a
 
 instance (Convertable a b) => MetaUnit Kilo a b where
-	metafactor _ = 1000
+	metafactor _ = 10^3
 	metashow _ = "k"
 
 data Mega a
 
 instance (Convertable a b) => MetaUnit Mega a b where
-	metafactor _ = 1000000
+	metafactor _ = 10^6
 	metashow _ = "M"
 
 data Giga a
 
 instance (Convertable a b) => MetaUnit Giga a b where
-	metafactor _ = 1000000000
+	metafactor _ = 10^9
 	metashow _ = "G"
 
 data Tera a
 
 instance (Convertable a b) => MetaUnit Tera a b where
-	metafactor _ = 1000000000000
+	metafactor _ = 10^12
 	metashow _ = "T"
 
 data Peta a
 
 instance (Convertable a b) => MetaUnit Peta a b where
-	metafactor _ = 1000000000000000
+	metafactor _ = 10^15
 	metashow _ = "P"
 
 data Exa a
 
 instance (Convertable a b) => MetaUnit Exa a b where
-	metafactor _ = 1000000000000000000
+	metafactor _ = 10^18
 	metashow _ = "E"
 
 data Zetta a
 
 instance (Convertable a b) => MetaUnit Zetta a b where
-	metafactor _ = 1000000000000000000000
+	metafactor _ = 10^21
 	metashow _ = "Z"
 
 data Yotta a
 
 instance (Convertable a b) => MetaUnit Yotta a b where
-	metafactor _ = 1000000000000000000000000
+	metafactor _ = 10^24
 	metashow _ = "Y"
 
 data Deci a
 data Centi a
 
 instance (Convertable a b) => MetaUnit Centi a b where
-	metafactor _ = 0.01
+	metafactor _ = 0.1^2
 	metashow _ = "c"
 
 data Mili a
 
 instance (Convertable a b) => MetaUnit Mili a b where
-	metafactor _ = 0.001
+	metafactor _ = 0.1^3
 	metashow _ = "m"
 
 data Micro a
 
 instance (Convertable a b) => MetaUnit Micro a b where
-	metafactor _ = 0.000001
+	metafactor _ = 0.1^6
 	metashow _ = "µ"
 
 data Nano a
 
 instance (Convertable a b) => MetaUnit Nano a b where
-	metafactor _ = 0.000000001
+	metafactor _ = 0.1^9
 	metashow _ = "n"
 
 data Pico a
 
 instance (Convertable a b) => MetaUnit Pico a b where
-	metafactor _ = 0.000000000001
+	metafactor _ = 0.1^12
 	metashow _ = "p"
 
 data Femto a
 
 instance (Convertable a b) => MetaUnit Femto a b where
-	metafactor _ = 0.000000000000001
+	metafactor _ = 0.1^15
 	metashow _ = "f"
 
 data Atto a
 
 instance (Convertable a b) => MetaUnit Atto a b where
-	metafactor _ = 0.000000000000000001
+	metafactor _ = 0.1^18
 	metashow _ = "a"
 
 data Zepto a
 
 instance (Convertable a b) => MetaUnit Zepto a b where
-	metafactor _ = 0.000000000000000000001
+	metafactor _ = 0.1^21
 	metashow _ = "z"
 
 data Yocto a
 
 instance (Convertable a b) => MetaUnit Yocto a b where
-	metafactor _ = 0.000000000000000000000001
+	metafactor _ = 0.1^24
 	metashow _ = "y"
 
 ------
 data Kibi a
 
 instance (Convertable a b) => MetaUnit Kibi a b where
-	metafactor _ = (Prelude.^) 2 10
+	metafactor _ = 2 ^ 10
 	metashow _ = "Ki"
 
 data Mebi a
 
 instance (Convertable a b) => MetaUnit Mebi a b where
-	metafactor _ = (Prelude.^) 2 20
+	metafactor _ = 2 ^ 20
 	metashow _ = "Mi"
 
 data Gibi a
 
 instance (Convertable a b) => MetaUnit Gibi a b where
-	metafactor _ = (Prelude.^) 2 30
+	metafactor _ = 2 ^ 30
 	metashow _ = "Gi"
 
 data Tebi a
 
 instance (Convertable a b) => MetaUnit Tebi a b where
-	metafactor _ = (Prelude.^) 2 40
+	metafactor _ = 2 ^ 40
 	metashow _ = "Ti"
 
 data Pebi a
 
 instance (Convertable a b) => MetaUnit Pebi a b where
-	metafactor _ = (Prelude.^) 2 50
+	metafactor _ = 2 ^ 50
 	metashow _ = "Pi"
 
 data Exbi a
 
 instance (Convertable a b) => MetaUnit Exbi a b where
-	metafactor _ = (Prelude.^) 2 60
+	metafactor _ = 2 ^ 60
 	metashow _ = "Ei"
 
 data Zebi a
 
 instance (Convertable a b) => MetaUnit Zebi a b where
-	metafactor _ = (Prelude.^) 2 70
+	metafactor _ = 2 ^ 70
 	metashow _ = "Zi"
 
 data Yobi a
 
 instance (Convertable a b) => MetaUnit Yobi a b where
-	metafactor _ = (Prelude.^) 2 80
+	metafactor _ = 2 ^ 80
 	metashow _ = "Yi"