Skip to content

Commit

Permalink
Fixed doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasPietzschmann committed Jul 17, 2024
1 parent cac275d commit 58e895d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Math/Haskellator/Internal/AstProcessingSteps/Evaluate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ execVar n = getVarBinding n >>= \case
return result

-- | Combine the Units of two Dimensions, by adding the powers of matching units.
--
-- >>> mergeUnits [UnitExp Meter 2, UnitExp Second 1, UnitExp Kilogram 1] [UnitExp Meter 1, UnitExp Second (-2)]
-- m^3*kg/s
mergeUnits :: Dimension -> Dimension -> Dimension
mergeUnits lhs rhs = [x{power = power x + power y} | (x, y) <- pairs] ++ lr ++ rr
where (pairs, (lr, rr)) = findPairs lhs rhs

-- | Combine the Units of two Dimensions, by subtracting the powers of matching units.
--
-- >>> subtractUnits [UnitExp Meter 2, UnitExp Second 1, UnitExp Kilogram 1] [UnitExp Meter 1, UnitExp Second (-2)]
-- m*s^3*kg
subtractUnits :: Dimension -> Dimension -> Dimension
Expand Down
2 changes: 2 additions & 0 deletions src/Math/Haskellator/Internal/AstProcessingSteps/Normalize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ normalize :: Expr -- ^ the 'Expr' tree to normalize
normalize = Right . foldExpr (Val . filterMultiplier . convertDimensionToBase) BinOp UnaryOp Conversion VarBindings Var

-- | Converts a value to its base dimension
--
-- >>> convertDimensionToBase $ Value 1 [UnitExp Kilometer 2, UnitExp Hour 1]
-- 3.6e9 m^2*s
convertDimensionToBase :: AstValue -> AstValue
Expand All @@ -28,6 +29,7 @@ convertDimensionToBase (Value v u) = foldr doIt (Value v []) u
in Value (v' * v'') (u'':u')

-- | 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
convertDimensionTo :: AstValue -> Dimension -> AstValue
Expand Down

0 comments on commit 58e895d

Please sign in to comment.