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

Language | Haskell2010 |

Defines the common constructors used to build quantities.

## Synopsis

# Documentation

defaultDefinitions :: Either (QuantityError Double) Definitions Source #

Default set of definitions that come predefined.

`>>>`

`import Data.Quantities`

fromString :: String -> Either (QuantityError Double) (Quantity Double) Source #

Create a Quantity by parsing a string. Uses an `UndefinedUnitError`

for
undefined units. Handles arithmetic expressions as well.

`>>>`

Right 25.0 meter / second`fromString "25 m/s"`

`>>>`

Left (UndefinedUnitError "fakeunit")`fromString "fakeunit"`

`>>>`

Right 2.0 foot`fromString "ft + 12in"`

This function also supports unit conversions, by placing "=>" in between
two valid expressions. This behavior is undefined (and returns a
`ScalingFactorError`

) if the quantity to be converted to has a magnitude.

`>>>`

Right 60.0 second`fromString "min => s"`

`>>>`

Right 2.5 foot`fromString "2 ft + 6 in => ft"`

`>>>`

Left (ScalingFactorError 3.0 foot)`fromString "m => 3 ft"`

Make sure not to use dimensional quantities in exponents.

`>>>`

Right 1.0 meter ** 2`fromString "m ** 2"`

`>>>`

Left (ParserError "Used non-dimensionless exponent in ( Right 1.0 meter ) ** ( Right 2.0 second )")`fromString "m ** (2s)"`

fromString' :: Definitions -> String -> Either (QuantityError Double) (Quantity Double) Source #

Create quantities with custom definitions.

`>>>`

`let myDefString = defaultDefString ++ "\nmy_unit = 100 s"`

`>>>`

`let (Right d) = readDefinitions myDefString`

`>>>`

`let myFromString = fromString' d`

`>>>`

Right 25.0 my_unit`myFromString "25 my_unit"`

unitsFromString :: String -> Either (QuantityError Double) CompoundUnit Source #

Parse units from a string. Equivalent to `fmap units . fromString`

`>>>`

Right newton second`unitsFromString "N * s"`