Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Models an expression tree
Examples:
>>>
show $ BinOp (Val $ Value 1.0 $ meter 1) Plus (BinOp (Val $ Value 2 $ multiplier 1) Mult (Val $ Value 3.0 $ meter 1))
"(1.0 m + (2.0 * 3.0 m))"
>>>
show $ BinOp (BinOp (Val $ Value 1.0 $ meter 1) Plus (Val $ Value 2.0 $ meter 1)) Mult (Val $ Value 3.0 $ multiplier 1)
"((1.0 m + 2.0 m) * 3.0)"
Synopsis
- type AstFold a b = ExceptT Error (State (Stack (Map String (Thunk a)))) b
- type AstValue = Value Dimension
- type Bindings a = [(String, a)]
- data Expr
- type SimpleAstFold a = AstFold a a
- data Thunk a
- data Value u = Value {}
- bindVar :: String -> Thunk a -> AstFold a ()
- bindVars :: Bindings (Thunk a) -> AstFold a ()
- foldExpr :: (AstValue -> a) -> (a -> Op -> a -> a) -> (Op -> a -> a) -> (a -> Dimension -> a) -> (Bindings a -> a -> a) -> (String -> a) -> Expr -> a
- getVarBinding :: String -> AstFold a (Thunk a)
- partiallyFoldExprM :: (AstValue -> SimpleAstFold a) -> (a -> Op -> a -> SimpleAstFold a) -> (Op -> a -> SimpleAstFold a) -> (a -> Dimension -> SimpleAstFold a) -> (Bindings Expr -> Expr -> SimpleAstFold a) -> (String -> SimpleAstFold a) -> Expr -> SimpleAstFold a
- runAstFold :: SimpleAstFold a -> Either Error a
- runInNewScope :: SimpleAstFold a -> SimpleAstFold a
Documentation
type AstFold a b = ExceptT Error (State (Stack (Map String (Thunk a)))) b Source #
Encapsulates the result b
of folding an expression tree and holds the current
state of variable bindings to values of type a
type Bindings a = [(String, a)] Source #
A list of variable bindings, mapping a name to an arbitrary value
The expression tree
type SimpleAstFold a = AstFold a a Source #
Simplified version of AstFold
that returns the same type as it binds to variables
A simple representation of a value with a unit. The unit's type is parameterized,
since the unit can be a simple Unit
or a Dimension
.
:: (AstValue -> a) | function that folds a value |
-> (a -> Op -> a -> a) | function that folds a binary expression |
-> (Op -> a -> a) | function that folds a unary expression |
-> (a -> Dimension -> a) | function that folds a conversion expression |
-> (Bindings a -> a -> a) | function that folds variable bindings |
-> (String -> a) | function that folds a variable |
-> Expr | the |
-> a | the resulting value |
Folds an expression tree
Retrieves the Thunk
bound to a variable name
partiallyFoldExprM :: (AstValue -> SimpleAstFold a) -> (a -> Op -> a -> SimpleAstFold a) -> (Op -> a -> SimpleAstFold a) -> (a -> Dimension -> SimpleAstFold a) -> (Bindings Expr -> Expr -> SimpleAstFold a) -> (String -> SimpleAstFold a) -> Expr -> SimpleAstFold a Source #
Like foldExpr
, but does not fold into variable bindings and returns a monadic
result
:: SimpleAstFold a | the computation to run |
-> Either Error a | the computation's result or an error |
Runs an SimpleAstFold
computation
:: SimpleAstFold a | the computation to run |
-> SimpleAstFold a | the computation's result |
Evaluates a SimpleAstFold
inside a new (and empty) scope