significant-figures-0.2.0.0: Calculate expressions involving significant figures.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.SigFig.PrettyPrint

Description

A module to unparse an expression.

Synopsis

Documentation

prettyPrint :: Expr -> Text Source #

Pretty print an expression, adding parentheses where needed. Text emitted from the pretty printer is intended to be able to be re-parsed, into the same expression tree.

Examples

Expand

If you want to create expressions to pretty print, utilize the functions in Types like below to make life easier.

>>> prettyPrint $ lMeasured 3 4.0
"4.00"
>>> prettyPrint $ add [lConstant 3, lMeasured 2 3.5]
"3c + 3.5"
>>> prettyPrint $ add [lConstant 3, mul [lMeasured 2 3.5, lConstant 2.7]]
"3c + 3.5 * 2.7c"
>>> prettyPrint $ mul [lConstant 3, add [lMeasured 2 3.5, lConstant 2.7]]
"3c * (3.5 + 2.7c)"