1. Thijs Alkemade
  2. haskell-unittyped

Commits

Takayuki Muranushi  committed 487d22c

Convertible is now 1-argument class.

base unit to dimension conversion is now type function rather than
functional dependencies. This will arrow stronger type inference.

  • Participants
  • Parent commits 6d8b341
  • Branches default

Comments (0)

Files changed (10)

File src/UnitTyped.hs

View file
     unit _ = M.insert (typeOf (error "typeOf" :: uni)) (fromNumber (error "fromNumber" :: NumberProxy value)) (unit (undefined :: Value a rest f))
 
 -- |Convertible is a class that models the fact that the base unit 'b'
--- has dimension 'DimType b'. c.f. the original class declaration used
+-- has dimension 'DimensionOf b'. c.f. the original class declaration used
 -- to be
 --
 -- > class Convertible (a :: [(*, Number)]) b | b -> a where
 --
--- the type 'a' now became 'DimType b' .
+-- the type 'a' now became 'DimensionOf b' .
 
 
 class Convertible b where
         -- |The multiplication factor to convert this base unit between other units in the same dimension.
         -- Only the ratio matters, which one is '1' is not important, as long as all are consistent.
-        factor :: (Fractional f) => ValueProxy (DimType b) b -> f
+        factor :: (Fractional f) => ValueProxy (DimensionOf b) b -> f
         -- |String representation of a base unit.
-        showunit :: ValueProxy (DimType b) b -> String
+        showunit :: ValueProxy (DimensionOf b) b -> String
 
-        type DimType b ::  [(*, Number)]
+        type DimensionOf b ::  [(*, Number)]
 
 
 -- | Shorthand to create a composed unit containing just one base unit.
 type U a = '[ '(a, POne) ]
 
 -- | Shorthand to create a 'Value' type from just one base unit.
-type (x :| b) = (Convertible b) => Value (DimType b) (U b) x
+type (x :| b) = (Convertible b) => Value (DimensionOf b) (U b) x
 
 
 
         {-# INLINE showunit' #-}
         showunit' _ = ""
 
-instance (Convertible b, MapEq a a') => Convertible' a' ('(b, POne) ': '[]) where
+instance (Convertible b, MapEq (DimensionOf b) a') => Convertible' a' ('(b, POne) ': '[]) where
         {-# INLINE factor' #-}
-        factor' _ = factor (undefined :: ValueProxy (DimType b) b)
+        factor' _ = factor (undefined :: ValueProxy (DimensionOf b) b)
         {-# INLINE showunit' #-}
-        showunit' _ = showunit (undefined :: ValueProxy (DimType b) b)
+        showunit' _ = showunit (undefined :: ValueProxy (DimensionOf b) b)
 
 instance (FromNumber value, Convertible' rec_dimension rest, MapNeg unit_dimension neg_unit_dimension,
           MapTimes value neg_unit_dimension times_neg_unit_dimension,
           MapMerge times_neg_unit_dimension dimension rec_dimension,
           Convertible unit,
-          unit_dimension ~ DimType unit
+          unit_dimension ~ DimensionOf unit
           ) => Convertible' dimension ('(unit, value) ': rest) where
         factor' _ = let
                         rec = factor' (undefined :: ValueProxy' rec_dimension rest)
 instance Convertible Count where
         factor _ = 1
         showunit _ = "#"
-        type DimType Count =  '[]
+        type DimensionOf Count =  '[]

File src/UnitTyped/Bytes.hs

View file
 {-# LANGUAGE DataKinds #-}
+{-# LANGUAGE TypeFamilies #-}
 -- |A module for working with amounts of bytes and bits.
 module UnitTyped.Bytes where
 
 data Byte
 	deriving Typeable
 
-instance Convertible DataDimension Byte where
+instance Convertible Byte where
 	factor _ = 1
 	showunit _ = "B"
+        type DimensionOf Byte = DataDimension 
 
 -- |A bit of data.
 data Bit
 	deriving Typeable
 
-instance Convertible DataDimension Bit where
+instance Convertible Bit where
 	factor _ = 0.125
 	showunit _ = "b"
-
+        type DimensionOf Bit = DataDimension 
 --
 
 -- |One byte.

File src/UnitTyped/SI.hs

View file
 {-# LANGUAGE OverlappingInstances #-}
 {-# LANGUAGE GADTs #-}
 {-# LANGUAGE EmptyDataDecls #-}
+{-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE TypeOperators #-}
 {-# LANGUAGE RankNTypes #-}
 {-# LANGUAGE DataKinds #-}
 instance Convertible Mole where
 	factor _ = 6.0221417930e23
 	showunit _ = "mole"
-        type DimType Mole = '[]
+        type DimensionOf Mole = '[]
 ----
 -- Length
 ----
 data Meter
 	deriving Typeable
 
-instance Convertible LengthDimension Meter where
+instance Convertible Meter where
 	factor _ = 1
 	showunit _ = "m"
-
+        type DimensionOf Meter = LengthDimension
 ----
 -- Time
 ----
 data Second
 	deriving Typeable
 
-instance Convertible TimeDimension Second where
+instance Convertible Second where
 	factor _ = 1
 	showunit _ = "s"
-
+        type DimensionOf Second = TimeDimension
 ----
 -- Mass
 ----
 data Gram
 	deriving Typeable
 
-instance Convertible MassDimension Gram where
+instance Convertible Gram where
 	factor _ = 0.001
 	showunit _ = "g"
-
+        type DimensionOf Gram = MassDimension
 ----
 -- Temperature
 ----
 data Kelvin
 	deriving Typeable
 
-instance Convertible TemperatureDimension Kelvin where
+instance Convertible Kelvin where
 	factor _ = 1
 	showunit _ = "K"
-
+        type DimensionOf Kelvin = TemperatureDimension
 ----
 -- Current
 ----
 data Ampere
 	deriving Typeable
 
-instance Convertible CurrentDimension Ampere where
+instance Convertible Ampere where
 	factor _ = 1
 	showunit _ = "A"
-
+        type DimensionOf Ampere = CurrentDimension 
 ----
 -- Luminous
 ----
 data Candela
 	deriving Typeable
 
-instance Convertible LuminousDimension Candela where
+instance Convertible Candela where
 	factor _ = 1
 	showunit _ = "cd"
-
+        type DimensionOf Candela = LuminousDimension
 ----
 
 -- |One thing (#).

File src/UnitTyped/SI/Derived.hs

View file
 {-# LANGUAGE OverlappingInstances #-}
 {-# LANGUAGE GADTs #-}
 {-# LANGUAGE EmptyDataDecls #-}
+{-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE TypeOperators #-}
 {-# LANGUAGE RankNTypes #-}
 {-# LANGUAGE DataKinds #-}
 data Knot
 	deriving Typeable
 
-instance Convertible Speed Knot where
+instance Convertible Knot where
 	factor _ = 1852 / 3600
 	showunit _ = "kn"
-
+        type DimensionOf Knot = Speed
 --
 
 
 data Newton
 	deriving Typeable
 
-instance Convertible Force Newton where
+instance Convertible Newton where
 	factor _ = 1
 	showunit _ = "N"
-
+        type DimensionOf Newton = Force 
 --
 
 -- |Energy. @Length^2 Time^-2 Mass^1@.
 data Joule
 	deriving Typeable
 
-instance Convertible Energy Joule where
+instance Convertible Joule where
 	factor _ = 1
 	showunit _ = "J"
+        type DimensionOf Joule = Energy 
 
 -- |Unit of energy (eV).
 data Ev
 	deriving Typeable
 
-instance Convertible Energy Ev where
+instance Convertible Ev where
 	factor _ = 1.60217656535e-19
 	showunit _ = "eV"
-
+        type DimensionOf Ev = Energy 
 --
 
 -- |Energy. @Length^2 Time^-3 Mass^1@.
 data Watt
 	deriving Typeable
 
-instance Convertible Power Watt where
+instance Convertible Watt where
 	factor _ = 1
 	showunit _ = "W"
-
+        type DimensionOf Watt = Power
 --
 
 -- |Energy. @Length^-1 Time^-2 Mass^1@.
 data Pascal
 	deriving Typeable
 
-instance Convertible Pressure Pascal where
+instance Convertible Pascal where
 	factor _ = 1
 	showunit _ = "Pa"
+        type DimensionOf Pascal = Pressure
 
 -- |Unit of pressure (bar).
 data Bar
 	deriving Typeable
 
-instance Convertible Pressure Bar where
+instance Convertible Bar where
 	factor _ = 1e5
 	showunit _ = "bar"
+        type DimensionOf Bar = Pressure
 
 -- |Unit of pressure (mmHg).
 data MmHg
 	deriving Typeable
 
-instance Convertible Pressure MmHg where
+instance Convertible MmHg where
 	factor _ = 133.322
 	showunit _ = "mmHg"
-
+        type DimensionOf MmHg = Pressure 
 --
 
 -- |Electric charge. @Time^1 Current^1@.
 data Coulomb
 	deriving Typeable
 
-instance Convertible Charge Coulomb where
+instance Convertible Coulomb where
 	factor _ = 1
 	showunit _ = "C"
-
+        type DimensionOf Coulomb = Charge
 --
 
 -- |Electric potential. @Time^-3 Current^-1 Mass^1 Length^2@.
-type Potential = '[ '(Current, NOne), '(Mass, POne), '(Length, PTwo), '(Time, NThree) ]
+type ElectricPotential = '[ '(Current, NOne), '(Mass, POne), '(Length, PTwo), '(Time, NThree) ]
 
 -- |Unit of potential (V).
 data Volt
 	deriving Typeable
 
-instance Convertible Potential Volt where
+instance Convertible Volt where
 	factor _ = 1
 	showunit _ = "V"
-
+        type DimensionOf Volt = ElectricPotential 
 --
 
 -- |Electric capacitance. @Current^2 Mass^-1 Length^2 Time^4@.
 data Farad
 	deriving Typeable
 
-instance Convertible Capacitance Farad where
+instance Convertible Farad where
 	factor _ = 1
 	showunit _ = "F"
-
+        type DimensionOf Farad = Capacitance 
 --
 
 -- |Electric resistance. @Current^-2 Time^-3 Length^2 Mass^1@.
 data Ohm
 	deriving Typeable
 
-instance Convertible Resistance Ohm where
+instance Convertible Ohm where
 	factor _ = 1
 	showunit _ = "Ω"
-
+        type DimensionOf Ohm = Resistance 
 --
 
 -- |Electric conductance. @Current^2 Mass^-1 Length^-2 Time^3@.
 data Siemens
 	deriving Typeable
 
-instance Convertible Conductance Siemens where
+instance Convertible Siemens where
 	factor _ = 1
 	showunit _ = "S"
-
+        type DimensionOf Siemens = Conductance 
 --
 
 -- |Magnetic flux. @Current^-1 Length^2 Mass^1 Time^-2@.
-type Flux = '[ '(Current, NOne), '(Length, PTwo), '(Mass, POne), '(Time, NTwo) ]
+type MagneticFlux = '[ '(Current, NOne), '(Length, PTwo), '(Mass, POne), '(Time, NTwo) ]
 
 -- |Unit of magnetic flux (Wb).
 data Weber
 	deriving Typeable
 
-instance Convertible Flux Weber where
+instance Convertible Weber where
 	factor _ = 1
 	showunit _ = "Wb"
+        type DimensionOf Weber = MagneticFlux
 
 --
 
 -- |Magnetic field strength. @Time^-2 Mass^1 Current^-1@.
-type FluxDensity = '[ '(Time, NTwo), '(Mass, POne), '(Current, NOne) ]
+type MagneticFluxDensity = '[ '(Time, NTwo), '(Mass, POne), '(Current, NOne) ]
 
 -- |Unit of magnetic field strength (T).
 data Tesla
 	deriving Typeable
 
-instance Convertible FluxDensity Tesla where
+instance Convertible Tesla where
 	factor _ = 1
 	showunit _ = "T"
-
+        type DimensionOf Tesla = MagneticFluxDensity 
 --
 
 -- |Inductance. @Current^-2 Time^-2 Mass^1 Length^2@.
 data Henry
 	deriving Typeable
 
-instance Convertible Inductance Henry where
+instance Convertible Henry where
 	factor _ = 1
 	showunit _ = "H"
-
+        type DimensionOf Henry = Inductance
 --
 
 -- |One knot.
 coulomb = one
 
 -- |One volt.
-volt :: (Fractional f) => Value Potential (U Volt) f
+volt :: (Fractional f) => Value ElectricPotential (U Volt) f
 volt = one
 
 -- |One farad.
 siemens = one
 
 -- |One weber.
-weber :: (Fractional f) => Value Flux (U Weber) f
+weber :: (Fractional f) => Value MagneticFlux (U Weber) f
 weber = one
 
 -- |One tesla.
-tesla :: (Fractional f) => Value FluxDensity (U Tesla) f
+tesla :: (Fractional f) => Value MagneticFluxDensity (U Tesla) f
 tesla = one
 
 -- |One henry.

File src/UnitTyped/SI/Derived/Count.hs

View file
 {-# LANGUAGE OverlappingInstances #-}
 {-# LANGUAGE GADTs #-}
 {-# LANGUAGE EmptyDataDecls #-}
+{-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE TypeOperators #-}
 {-# LANGUAGE RankNTypes #-}
 {-# LANGUAGE DataKinds #-}
 data Percentage
 	deriving Typeable
 
-instance Convertible '[] Percentage where
+instance Convertible Percentage where
 	factor _ = 0.01
 	showunit _ = "%"
+        type DimensionOf Percentage = '[]
 
 -- |Per mille: 1‰ == 0.001
 data Permil
 	deriving Typeable
 
-instance Convertible '[] Permil where
+instance Convertible Permil where
 	factor _ = 0.001
 	showunit _ = "‰"
+        type DimensionOf Permil = '[]
 
 -- |Parts per million: 1 ppm == 0.1^6
 data Ppm
 	deriving Typeable
 
-instance Convertible '[] Ppm where
+instance Convertible Ppm where
 	factor _ = 0.1^6
 	showunit _ = "ppm"
+        type DimensionOf Ppm = '[]
 
 -- |Parts per billion: 1 ppb == 0.1^9
 data Ppb
 	deriving Typeable
 
-instance Convertible '[] Ppb where
+instance Convertible Ppb where
 	factor _ = 0.1^9
 	showunit _ = "ppb"
+        type DimensionOf Ppb = '[]
 
 -- |Parts per trillion: 1 ppt == 0.1^12
 data Ppt
 	deriving Typeable
 
-instance Convertible '[] Ppt where
+instance Convertible Ppt where
 	factor _ = 0.1^12
 	showunit _ = "ppt"
+        type DimensionOf Ppt = '[]
 
 -- |Angles are dimensionless, these are radians (rad).
 data Radian
 	deriving Typeable
 
-instance Convertible '[] Radian where
+instance Convertible Radian where
 	factor _ = 1
 	showunit _ = "rad"
+        type DimensionOf Radian = '[]
 
 -- |Angles are dimensionless, these are degrees (˚).
 data Degree
 	deriving Typeable
 
-instance Convertible '[] Degree where
+instance Convertible Degree where
 	factor _ = 3.141592653589793 / 180
 	showunit _ = "°"
+        type DimensionOf Degree = '[]
 
 --
 

File src/UnitTyped/SI/Derived/Length.hs

View file
 {-# LANGUAGE OverlappingInstances #-}
 {-# LANGUAGE GADTs #-}
 {-# LANGUAGE EmptyDataDecls #-}
+{-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE TypeOperators #-}
 {-# LANGUAGE RankNTypes #-}
 {-# LANGUAGE DataKinds #-}
 data Mile
 	deriving Typeable
 
-instance Convertible LengthDimension Mile where
+instance Convertible Mile where
 	factor _ = 1609.344
 	showunit _ = "mile"
+        type DimensionOf Mile = LengthDimension
 
 -- |The international inch (in).
 data Inch
 	deriving Typeable
 
-instance Convertible LengthDimension Inch where
+instance Convertible Inch where
 	factor _ = 0.0254
 	showunit _ = "in"
+        type DimensionOf Inch = LengthDimension
 
 -- |The international yard (yd).
 data Yard
 	deriving Typeable
 
-instance Convertible LengthDimension Yard where
+instance Convertible Yard where
 	factor _ = 0.9144
 	showunit _ = "yd"
+        type DimensionOf Yard = LengthDimension
 
 -- |The international foot (ft).
 data Foot
 	deriving Typeable
 
-instance Convertible LengthDimension Foot where
+instance Convertible Foot where
 	factor _ = 0.3048
 	showunit _ = "ft"
+        type DimensionOf Foot = LengthDimension
 
 -- |Ångström, length unit for atoms and molecules (Å).
 data Ångström
 	deriving Typeable
 
-instance Convertible LengthDimension Ångström where
+instance Convertible Ångström where
 	factor _ = 10e-10
 	showunit _ = "Å"
+        type DimensionOf Ångström = LengthDimension
 
 -- |Nautical miles (M).
 data NauticalMile
 	deriving Typeable
 
-instance Convertible LengthDimension NauticalMile where
+instance Convertible NauticalMile where
 	factor _ = 1852
 	showunit _ = "M"
+        type DimensionOf NauticalMile = LengthDimension
 
 ----
 -- 2 dimensional
 ----
 
 -- |Area: @Length^2@.
-type AreaUnit = '[ '(Length, PTwo) ]
+type AreaDimension = '[ '(Length, PTwo) ]
 
 -- |Area, often used in nuclear physics (b).
 data Barn
 	deriving Typeable
 
-instance Convertible AreaUnit Barn where
+instance Convertible Barn where
 	factor _ = 1e-28
 	showunit _ = "b"
-
+        type DimensionOf Barn = AreaDimension
 ----
 -- 3 dimensional
 ----
 
 -- |Volume: @Length^3@.
-type VolumeUnit = '[ '(Length, PThree) ]
+type VolumeDimension = '[ '(Length, PThree) ]
 
 -- |Liter, unit of volume (L).
 data Liter
 	deriving Typeable
 
-instance Convertible VolumeUnit Liter where
+instance Convertible Liter where
 	factor _ = 0.001
 	showunit _ = "L"
+        type DimensionOf Liter = VolumeDimension
+
 
 -- |Gallon, unit of volume (gallon).
 data Gallon
 	deriving Typeable
 
-instance Convertible VolumeUnit Gallon where
+instance Convertible Gallon where
 	factor _ = 0.00454609
 	showunit _ = "gallon"
+        type DimensionOf Gallon = VolumeDimension
 
 -- |Fluid ounce, unit of volume (fl oz).
 data FluidOunce
 	deriving Typeable
 
-instance Convertible VolumeUnit FluidOunce where
+instance Convertible FluidOunce where
 	factor _ = 0.0000284130625
 	showunit _ = "fl oz"
+        type DimensionOf FluidOunce = VolumeDimension
 
 --
 
 --
 
 -- |One barn (b).
-barn :: (Fractional f) => Value AreaUnit (U Barn) f
+barn :: (Fractional f) => Value AreaDimension (U Barn) f
 barn = one
 
 --
 
 -- |One liter (L).
-liter :: (Fractional f) => Value VolumeUnit (U Liter) f
+liter :: (Fractional f) => Value VolumeDimension (U Liter) f
 liter = one
 
 -- |One gallon (gallon).
-gallon :: (Fractional f) => Value VolumeUnit (U Gallon) f
+gallon :: (Fractional f) => Value VolumeDimension (U Gallon) f
 gallon = one
 
 -- |One fluid ounce (fl oz).
-fluid_ounce :: (Fractional f) => Value VolumeUnit (U FluidOunce) f
+fluid_ounce :: (Fractional f) => Value VolumeDimension (U FluidOunce) f
 fluid_ounce = one

File src/UnitTyped/SI/Derived/Mass.hs

View file
 {-# LANGUAGE OverlappingInstances #-}
 {-# LANGUAGE GADTs #-}
 {-# LANGUAGE EmptyDataDecls #-}
+{-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE TypeOperators #-}
 {-# LANGUAGE RankNTypes #-}
 {-# LANGUAGE DataKinds #-}
 data Pound
 	deriving Typeable
 
-instance Convertible MassDimension Pound where
+instance Convertible Pound where
 	factor _ = 0.45359237
 	showunit _ = "lb"
-
+        type DimensionOf Pound = MassDimension 
 --
 
 -- |One pound (lb).

File src/UnitTyped/SI/Derived/Time.hs

View file
 {-# LANGUAGE OverlappingInstances #-}
 {-# LANGUAGE GADTs #-}
 {-# LANGUAGE EmptyDataDecls #-}
+{-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE TypeOperators #-}
 {-# LANGUAGE RankNTypes #-}
 {-# LANGUAGE DataKinds #-}
 data Hour
 	deriving Typeable
 
-instance Convertible TimeDimension Hour where
+instance Convertible Hour where
 	factor _ = 3600
 	showunit _ = "h"
+        type DimensionOf Hour = TimeDimension 
 
 -- |Minute (min.).
 data Minute
 	deriving Typeable
 
-instance Convertible TimeDimension Minute where
+instance Convertible Minute where
 	factor _ = 60
 	showunit _ = "min."
+        type DimensionOf Minute = TimeDimension 
 
 -- |Day (day).
 data Day
 	deriving Typeable
 
-instance Convertible TimeDimension Day where
+instance Convertible Day where
 	factor _ = 86400
 	showunit _ = "day"
+        type DimensionOf Day = TimeDimension 
+
 
 -- |Year (yr). This is an average year in the Gregorian calender (so 365.2425 days).
 data Year
 	deriving Typeable
 
-instance Convertible TimeDimension Year where
+instance Convertible Year where
 	factor _ = 365.2425 * 24 * 60 * 60
 	showunit _ = "yr"
+        type DimensionOf Year = TimeDimension 
 
 -- |Month (month). Average length of a month (365.2425 / 12).
 data Month
 	deriving Typeable
 
-instance Convertible TimeDimension Month where
+instance Convertible Month where
 	factor _ = (365.2425 * 24 * 60 * 60) / 12
 	showunit _ = "month"
+        type DimensionOf Month = TimeDimension 
 
 -- |Julian year (a). This is an average year in the Julian calender (so 365.25 days). Still used in astronomy.
 data JulianYear
 	deriving Typeable
 
-instance Convertible TimeDimension JulianYear where
+instance Convertible JulianYear where
 	factor _ = 31557600
 	showunit _ = "a"
+        type DimensionOf JulianYear = TimeDimension 
 
 -- |Frequency in Hertz. (Hz)
 data Hertz
 	deriving Typeable
 
-instance Convertible '[ '(Time, Neg One) ] Hertz where
+instance Convertible Hertz where
 	factor _ = 1
 	showunit _ = "Hz"
+        type DimensionOf Hertz = '[ '(Time, Neg One) ]
 
 --
 

File src/UnitTyped/SI/Meta.hs

View file
 {-# LANGUAGE OverlappingInstances #-}
 {-# LANGUAGE GADTs #-}
 {-# LANGUAGE EmptyDataDecls #-}
+{-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE TypeOperators #-}
 {-# LANGUAGE RankNTypes #-}
 {-# LANGUAGE DataKinds #-}
 -- Meta-units
 ----
 
-data MetaProxy (m :: * -> *) (a :: [(*, Number)]) b
+data MetaProxy (m :: * -> *) {-(a :: [(*, Number)])-} b
 
-class (Convertible a b) => MetaUnit (m :: * -> *) a b where
-	metafactor :: (Fractional f) => MetaProxy m a b -> f
-	metashow :: (Fractional f) => MetaProxy m a b -> String
+class (Convertible b) => MetaUnit (m :: * -> *) b where
+	metafactor :: (Fractional f) => MetaProxy m b -> f
+	metashow :: (Fractional f) => MetaProxy m b -> String
 
-instance (MetaUnit m a b, Convertible a b) => Convertible a (m b) where
-	factor _ = metafactor (undefined :: MetaProxy m a b) * factor (undefined :: ValueProxy a b)
-	showunit v = metashow (undefined :: MetaProxy m a b) ++ showunit (undefined :: ValueProxy a b)
-
+instance (MetaUnit m b, Convertible b) => Convertible (m b) where
+	factor _ = metafactor (undefined :: MetaProxy m b) * factor (undefined :: ValueProxy (DimensionOf b) b)
+	showunit v = metashow (undefined :: MetaProxy m b) ++ showunit (undefined :: ValueProxy (DimensionOf b) b)
+        type DimensionOf (m b) = DimensionOf b
 --
 
 -- |Create a unit 10^1 times an existing unit.
 data Deca a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Deca a b where
+instance (Convertible b) => MetaUnit Deca {-a-} b where
 	metafactor _ = 10
 	metashow _ = "da"
 
 data Hecto a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Hecto a b where
+instance (Convertible b) => MetaUnit Hecto {-a-} b where
 	metafactor _ = 10^2
 	metashow _ = "h"
 
 data Kilo a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Kilo a b where
+instance (Convertible b) => MetaUnit Kilo {-a-} b where
 	metafactor _ = 10^3
 	metashow _ = "k"
 
 data Mega a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Mega a b where
+instance (Convertible b) => MetaUnit Mega {-a-} b where
 	metafactor _ = 10^6
 	metashow _ = "M"
 
 data Giga a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Giga a b where
+instance (Convertible b) => MetaUnit Giga {-a-} b where
 	metafactor _ = 10^9
 	metashow _ = "G"
 
 data Tera a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Tera a b where
+instance (Convertible b) => MetaUnit Tera {-a-} b where
 	metafactor _ = 10^12
 	metashow _ = "T"
 
 data Peta a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Peta a b where
+instance (Convertible b) => MetaUnit Peta {-a-} b where
 	metafactor _ = 10^15
 	metashow _ = "P"
 
 data Exa a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Exa a b where
+instance (Convertible b) => MetaUnit Exa {-a-} b where
 	metafactor _ = 10^18
 	metashow _ = "E"
 
 data Zetta a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Zetta a b where
+instance (Convertible b) => MetaUnit Zetta {-a-} b where
 	metafactor _ = 10^21
 	metashow _ = "Z"
 
 data Yotta a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Yotta a b where
+instance (Convertible b) => MetaUnit Yotta {-a-} b where
 	metafactor _ = 10^24
 	metashow _ = "Y"
 
 data Deci a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Deci a b where
+instance (Convertible b) => MetaUnit Deci {-a-} b where
 	metafactor _ = 0.1
 	metashow _ = "d"
 
 data Centi a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Centi a b where
+instance (Convertible b) => MetaUnit Centi {-a-} b where
 	metafactor _ = 0.1^2
 	metashow _ = "c"
 
 data Mili a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Mili a b where
+instance (Convertible b) => MetaUnit Mili {-a-} b where
 	metafactor _ = 0.1^3
 	metashow _ = "m"
 
 data Micro a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Micro a b where
+instance (Convertible b) => MetaUnit Micro {-a-} b where
 	metafactor _ = 0.1^6
 	metashow _ = "µ"
 
 data Nano a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Nano a b where
+instance (Convertible b) => MetaUnit Nano {-a-} b where
 	metafactor _ = 0.1^9
 	metashow _ = "n"
 
 data Pico a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Pico a b where
+instance (Convertible b) => MetaUnit Pico {-a-} b where
 	metafactor _ = 0.1^12
 	metashow _ = "p"
 
 data Femto a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Femto a b where
+instance (Convertible b) => MetaUnit Femto {-a-} b where
 	metafactor _ = 0.1^15
 	metashow _ = "f"
 
 data Atto a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Atto a b where
+instance (Convertible b) => MetaUnit Atto {-a-} b where
 	metafactor _ = 0.1^18
 	metashow _ = "a"
 
 data Zepto a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Zepto a b where
+instance (Convertible b) => MetaUnit Zepto {-a-} b where
 	metafactor _ = 0.1^21
 	metashow _ = "z"
 
 data Yocto a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Yocto a b where
+instance (Convertible b) => MetaUnit Yocto {-a-} b where
 	metafactor _ = 0.1^24
 	metashow _ = "y"
 
 data Kibi a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Kibi a b where
+instance (Convertible b) => MetaUnit Kibi {-a-} b where
 	metafactor _ = 2 ^ 10
 	metashow _ = "Ki"
 
 data Mebi a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Mebi a b where
+instance (Convertible b) => MetaUnit Mebi {-a-} b where
 	metafactor _ = 2 ^ 20
 	metashow _ = "Mi"
 
 data Gibi a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Gibi a b where
+instance (Convertible b) => MetaUnit Gibi {-a-} b where
 	metafactor _ = 2 ^ 30
 	metashow _ = "Gi"
 
 data Tebi a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Tebi a b where
+instance (Convertible b) => MetaUnit Tebi {-a-} b where
 	metafactor _ = 2 ^ 40
 	metashow _ = "Ti"
 
 data Pebi a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Pebi a b where
+instance (Convertible b) => MetaUnit Pebi {-a-} b where
 	metafactor _ = 2 ^ 50
 	metashow _ = "Pi"
 
 data Exbi a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Exbi a b where
+instance (Convertible b) => MetaUnit Exbi {-a-} b where
 	metafactor _ = 2 ^ 60
 	metashow _ = "Ei"
 
 data Zebi a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Zebi a b where
+instance (Convertible b) => MetaUnit Zebi {-a-} b where
 	metafactor _ = 2 ^ 70
 	metashow _ = "Zi"
 
 data Yobi a
 	deriving Typeable
 
-instance (Convertible a b) => MetaUnit Yobi a b where
+instance (Convertible b) => MetaUnit Yobi {-a-} b where
 	metafactor _ = 2 ^ 80
 	metashow _ = "Yi"
 
 ----
 
 -- |Take a unit and return one deca(unit).
-deca :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Deca b)) f
+deca :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Deca b)) f
 {-# INLINE deca #-}
 deca (Value x) = (Value x)
 
 -- |Take a unit and return one hecto(unit).
-hecto :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Hecto b)) f
+hecto :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Hecto b)) f
 {-# INLINE hecto #-}
 hecto (Value x) = (Value x)
 
 -- |Take a unit and return one kilo(unit).
-kilo :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Kilo b)) f
+kilo :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Kilo b)) f
 {-# INLINE kilo #-}
 kilo (Value x) = (Value x)
 
 -- |Take a unit and return one mega(unit).
-mega :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Mega b)) f
+mega :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Mega b)) f
 mega (Value x) = (Value x)
 
 -- |Take a unit and return one giga(unit).
-giga :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Giga b)) f
+giga :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Giga b)) f
 giga (Value x) = (Value x)
 
 -- |Take a unit and return one tera(unit).
-tera :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Tera b)) f
+tera :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Tera b)) f
 tera (Value x) = (Value x)
 
 -- |Take a unit and return one peta(unit).
-peta :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Peta b)) f
+peta :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Peta b)) f
 peta (Value x) = (Value x)
 
 -- |Take a unit and return one exa(unit).
-exa :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Exa b)) f
+exa :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Exa b)) f
 exa (Value x) = (Value x)
 
 -- |Take a unit and return one zetta(unit).
-zetta :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Zetta b)) f
+zetta :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Zetta b)) f
 zetta (Value x) = (Value x)
 
 -- |Take a unit and return one yotta(unit).
-yotta :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Yotta b)) f
+yotta :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Yotta b)) f
 yotta (Value x) = (Value x)
 
 -- |Take a unit and return one deci(unit).
-deci :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Deci b)) f
+deci :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Deci b)) f
 deci (Value x) = (Value x)
 
 -- |Take a unit and return one centi(unit).
-centi :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Centi b)) f
+centi :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Centi b)) f
 centi (Value x) = (Value x)
 
 -- |Take a unit and return one mili(unit).
-mili :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Mili b)) f
+mili :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Mili b)) f
 mili (Value x) = (Value x)
 
 -- |Take a unit and return one micro(unit).
-micro :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Micro b)) f
+micro :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Micro b)) f
 micro (Value x) = (Value x)
 
 -- |Take a unit and return one nano(unit).
-nano :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Nano b)) f
+nano :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Nano b)) f
 nano (Value x) = (Value x)
 
 -- |Take a unit and return one pico(unit).
-pico :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Pico b)) f
+pico :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Pico b)) f
 pico (Value x) = (Value x)
 
 -- |Take a unit and return one femto(unit).
-femto :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Femto b)) f
+femto :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Femto b)) f
 femto (Value x) = (Value x)
 
 -- |Take a unit and return one atto(unit).
-atto :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Atto b)) f
+atto :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Atto b)) f
 atto (Value x) = (Value x)
 
 -- |Take a unit and return one zepto(unit).
-zepto :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Zepto b)) f
+zepto :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Zepto b)) f
 zepto (Value x) = (Value x)
 
 -- |Take a unit and return one yocto(unit).
-yocto :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Yocto b)) f
+yocto :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Yocto b)) f
 yocto (Value x) = (Value x)
 
 --
 
 -- |Take a unit and return one kibi(unit).
-kibi :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Kibi b)) f
+kibi :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Kibi b)) f
 kibi (Value x) = (Value x)
 
 -- |Take a unit and return one mebi(unit).
-mebi :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Mebi b)) f
+mebi :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Mebi b)) f
 mebi (Value x) = (Value x)
 
 -- |Take a unit and return one gibi(unit).
-gibi :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Gibi b)) f
+gibi :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Gibi b)) f
 gibi (Value x) = (Value x)
 
 -- |Take a unit and return one tebi(unit).
-tebi :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Tebi b)) f
+tebi :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Tebi b)) f
 tebi (Value x) = (Value x)
 
 -- |Take a unit and return one pebi(unit).
-pebi :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Pebi b)) f
+pebi :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Pebi b)) f
 pebi (Value x) = (Value x)
 
 -- |Take a unit and return one exbi(unit).
-exbi :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Exbi b)) f
+exbi :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Exbi b)) f
 exbi (Value x) = (Value x)
 
 -- |Take a unit and return one zebi(unit).
-zebi :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Zebi b)) f
+zebi :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Zebi b)) f
 zebi (Value x) = (Value x)
 
 -- |Take a unit and return one yobi(unit).
-yobi :: (Convertible a b, Fractional f) => Value a (U b) f -> Value a (U (Yobi b)) f
+yobi :: (Convertible b, Fractional f) => Value a (U b) f -> Value a (U (Yobi b)) f
 yobi (Value x) = (Value x)

File src/UnitTyped/SI/Show.hs

View file
 --
 -- >>> meta_str meter (c |*| 1 *| year)
 -- "9 Pm, 460 Tm, 536 Gm, 207 Mm, 68 km, 16 m"
-meta_str :: (Convertible' a b, Convertible c d, MapEq a c) => Value c (U d) Rational -> Value a b Rational -> String
+meta_str :: (Convertible' a b, Convertible d, c ~ DimensionOf d, MapEq a c) => Value c (U d) Rational -> Value a b Rational -> String
 meta_str unit v = format_end (yocto unit) $ format (zepto unit) $ format (atto unit) $ format (femto unit)
 					$ format (pico unit) $ format (nano unit) $ format (micro unit) $ format (mili unit)
 					$ format unit $ format (kilo unit) $ format (mega unit) $ format (giga unit)