- type Exporter = Functions -> FilePath -> IO ()
- simplifyExpr :: [Expr -> Expr] -> Expr -> Expr
- commonRuleHigherPrec :: Expr -> Expr
- commonRuleAtomic :: Expr -> Expr
- commonRuleLeftToRight :: Expr -> Expr
- commonRuleAssocRight :: Expr -> Expr
- commonRuleFuncOp :: Expr -> Expr
- commonRulesForSimplifyingExprs :: [Expr -> Expr]
- ruleIfRight :: Expr -> Expr
- ruleRightToLeft :: Expr -> Expr
- applyFirstMatch :: [Expr -> Expr] -> Expr -> Expr
- findFixed :: Eq a => (a -> a) -> a -> a
The type of a function to export (user) functions to a file.
Simplify an expression by applying rules top-down throughout the expression tree and repeatedly until there is no change. This is intended for removing extra parentheses, but could be used for other forms of simplification.
Should each rule also know the level in the original expr tree, with 0 = top level (root)? That would require additional arguments.
Common rules for simplifying parentheses.
Remove ()'s around a higher precedence operator: e.g., (a * b) + c ==> a * b + c a + (b * c) ==> a + b * c
Remove ()'s around an atomic expression -- a variable, literal, or list
Remove ()'s in the case of (a op1 b) op2 c, if op1 and op2 have the same precedence, and both group left to right, since left to right evaluation makes them unnecessary.
A list of common rules for simplifying expressions. Does *not* include ruleIfRight, since that works for Haskell but not Python.
Remove ()'s in the case of a op (b op c) if op groups right to left, and note that it is the same operator op in both places (though I don't know if that restriction is necessary). This applies to (:) in Haskell, for example: x : y : zs == x : (y : zs)
Try the first rule in a list to see if it changes an expression, returning the new expression if it does; otherwise, try the next rule, and so on; if no rule changes the expression, then return the expression. (Note that (applyFirstMatch rules) is itself a rule.)