haskellator-0.1.0.0: SI-Units supporting calculator
Safe HaskellSafe-Inferred
LanguageHaskell2010

Math.Haskellator.Internal.AstProcessingSteps.Normalize

Description

Normalizes the expression tree generated by the Parser to a tree that can be evaluated.

Synopsis

Documentation

convertDimensionTo :: AstValue -> Dimension -> AstValue Source #

Converts a value to a given dimension. Throws if the conversion is not possible.

>>> convertDimensionTo (Value 3600000000 [UnitExp Meter 2, UnitExp Second 1]) [UnitExp Kilometer 2, UnitExp Hour 1]
1.0 h*km^2

convertDimensionToBase :: AstValue -> AstValue Source #

Converts a value to its base dimension

>>> convertDimensionToBase $ Value 1 [UnitExp Kilometer 2, UnitExp Hour 1]
3.6e9 m^2*s

normalize Source #

Arguments

:: Expr

the Expr tree to normalize

-> Either Error Expr

the normalized Expr tree

Normalize all values inside the tree to their base units

tryConvertDimensionTo :: AstValue -> Dimension -> Maybe AstValue Source #

Tries to convert a value to a given dimension. Returns Nothing if the conversion is not possible. See convertDimensionTo for an example.