jinquantities-0.1.1: Unit conversion and manipulation library.

Safe Haskell Safe Haskell2010

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.

Convert a quantity to its base units.

Converts a composite unit to its base quantity

Converts a simple unit to its base quantity.

Computes dimensionality of quantity.

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


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.