jinquantities-0.1.0: Unit conversion and manipulation library.

Safe HaskellSafe
LanguageHaskell2010

Data.Quantities.Convert

Description

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

Synopsis

Documentation

>>> import Control.Applicative
>>> import Data.Quantities

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

Convert quantity to given units.

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

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

Convert a quantity to its base units.

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

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.

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

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.