Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

Module to perform unit conversions, compute dimensionality, and convert to base units.

## Synopsis

- convert :: Fractional a => Quantity a -> CompoundUnit -> Either (QuantityError a) (Quantity a)
- convertBase :: Fractional a => Quantity a -> Quantity a
- convert' :: Fractional a => Definitions -> Quantity a -> CompoundUnit -> Either (QuantityError a) (Quantity a)
- convertBase' :: Fractional a => Definitions -> Quantity a -> Quantity a
- toBase :: Definitions -> [SimpleUnit] -> Quantity Double
- simpleToBase :: Definitions -> SimpleUnit -> Quantity Double
- dimensionality :: Quantity a -> CompoundUnit
- dimensionality' :: Definitions -> [SimpleUnit] -> [SimpleUnit]
- addQuants :: Fractional a => Quantity a -> Quantity a -> Either (QuantityError a) (Quantity a)
- subtractQuants :: Fractional a => Quantity a -> Quantity a -> Either (QuantityError a) (Quantity a)
- linearQuants :: Fractional a => (a -> a -> a) -> Quantity a -> Quantity a -> Either (QuantityError a) (Quantity a)

# Documentation

`>>>`

`import Control.Applicative`

`>>>`

`import Data.Quantities`

convert :: Fractional a => Quantity a -> CompoundUnit -> Either (QuantityError a) (Quantity a) Source #

Convert quantity to given units.

`>>>`

Right (Right 3.280839895013123 foot)`convert <$> fromString "m" <*> unitsFromString "ft"`

convertBase :: Fractional a => Quantity a -> Quantity a Source #

Convert a quantity to its base units.

`>>>`

Right 1000.0 gram meter / second ** 2`convertBase <$> fromString "newton"`

convert' :: Fractional a => Definitions -> Quantity a -> CompoundUnit -> Either (QuantityError a) (Quantity a) Source #

Convert quantity to given units.

convertBase' :: Fractional a => Definitions -> Quantity a -> Quantity a Source #

Convert a quantity to its base units.

toBase :: Definitions -> [SimpleUnit] -> Quantity Double Source #

Converts a composite unit to its base quantity

simpleToBase :: Definitions -> SimpleUnit -> Quantity Double Source #

Converts a simple unit to its base quantity.

dimensionality :: Quantity a -> CompoundUnit Source #

Computes dimensionality of quantity.

`>>>`

Right [length] [mass] / [time] ** 2`dimensionality <$> fromString "newton"`

dimensionality' :: Definitions -> [SimpleUnit] -> [SimpleUnit] Source #

Computes dimensionality of a list of SimpleUnits. Stores the dimensionality as a list of SimpleUnits as well, so we don't need a whole new type.

addQuants :: Fractional a => Quantity a -> Quantity a -> Either (QuantityError a) (Quantity a) Source #

Adds two quantities. Second quantity is converted to units of first quantity.

subtractQuants :: Fractional a => Quantity a -> Quantity a -> Either (QuantityError a) (Quantity a) Source #

Subtract two quantities. Second quantity is converted to units of first quantity.

linearQuants :: Fractional a => (a -> a -> a) -> Quantity a -> Quantity a -> Either (QuantityError a) (Quantity a) Source #

Helper function used in addQuants and subtractQuants.