1. Thijs Alkemade
  2. haskell-unittyped

Commits

Thijs Alkemade  committed 462d5d9

Added some more syntactic sugar, fix typo in README.

  • Participants
  • Parent commits 8291fb4
  • Branches default

Comments (0)

Files changed (2)

File README.md

View file
  • Ignore whitespace
 UnitTyped is a Haskell library for type-safe calculations on numbers with units.
 
-It comes with all SI units and a large number of units derived from them, but it also makes it very easy to add new dimensions and units. It can give new definitions of *, /, +, -, ==, <, <=, > and >= to make notation as natural as possible. To define a new unit, only the multiplication factor (and a string to dispaly it) is required. From just that, all other conversions can be inferred.
+It comes with all SI units and a large number of units derived from them, but it also makes it very easy to add new dimensions and units. It can give new definitions of *, /, +, -, ==, <, <=, > and >= to make notation as natural as possible. To define a new unit, only the multiplication factor and a string to display it is required. From just that, all other conversions can be inferred.
 
 While it uses a large number of Haskell extensions, all units and dimensions are empty datatypes, so should not be a burden at runtime.
 
 coerce can be used to change from one unit to a different unit in the same dimension:
 
 	:::haskell
-		*Main> coerce ((120 kilo meter / hour) * 20 minute) mile
+		*Main> (120 kilo meter / hour) * 20 minute `as` mile
 		24.854847689493358 mile
 
 See [the wiki][1] for more complicated examples.

File src/UnitTyped.hs

View file
  • Ignore whitespace
 (~.) :: (Convertable a b, Convertable c d, Fractional f, UnitEq a c True) => Value f a b -> Value f c d -> Value f c d
 (~.) = coerce
 
+infixl 5 `as`
+
+as :: (Convertable a b, Convertable c d, Fractional f, UnitEq a c True) => Value f a b -> Value f c d -> Value f c d
+as = coerce
+
 data Mul b d
 
 data Div b d
 (.*.) :: (Fractional f, Convertable a b, Convertable c d, UnitMerge a c u) => Value f a b -> Value f c d -> Value f u (Mul b d)
 a .*. b = mkVal (val a * val b)
 
-(./.) :: (Fractional f, Convertable a b, Convertable c d, UnitMerge a c' u, UnitNeg c c') => Value f a b -> Value f c d -> Value f u (Div b d)
+(./.), per :: (Fractional f, Convertable a b, Convertable c d, UnitMerge a c' u, UnitNeg c c') => Value f a b -> Value f c d -> Value f u (Div b d)
 a ./. b = mkVal (val a / val b)
+per = (./.)
 
 (.+.) :: (Fractional f, Convertable a b, Convertable c d, UnitEq c a True) => Value f a b -> Value f c d -> Value f a b
 a .+. b = mkVal (val a + val (coerce b a))