yap-0.2: yet another prelude - a simplistic refactoring with algebraic classes

Portabilityportable
Stabilityprovisional
Maintainerross@soi.city.ac.uk
Safe HaskellSafe-Infered

Data.YAP.Quantity

Description

An example instance of the new classes: numeric quantities with unit types. You can only compare and add quantities that use the same units.

Synopsis

Documentation

newtype Quantity u a Source

Quantities of a numeric type a, in units encoded by the phantom type parameter u. For example, types for counting apples and oranges can be defined as:

 data Apple
 data Orange
 type Apples = Quantity Apple Int
 type Oranges = Quantity Orange Int

You can't compare Apples with Oranges (or add them). You can add Apples to Apples, but not multiply them.

A full dimensional system keeping track of units while modelling multiplication and division will require type-level functions.

Constructors

Quantity a 

Instances

Eq a => Eq (Quantity u a) 
Ord a => Ord (Quantity u a) 
Read a => Read (Quantity u a) 
Show a => Show (Quantity u a) 
AbelianGroup a => AbelianGroup (Quantity u a)