sifflet-2.3.0: Simple, visual, functional language for learning about recursion.

Safe HaskellSafe
LanguageHaskell2010

Language.Sifflet.Export.Exporter

Synopsis

Documentation

type Exporter = Functions -> FilePath -> IO () Source

The type of a function to export (user) functions to a file.

simplifyExpr :: [Expr -> Expr] -> Expr -> Expr Source

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.

commonRuleHigherPrec :: Expr -> Expr Source

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

commonRuleAtomic :: Expr -> Expr Source

Remove ()'s around an atomic expression -- a variable, literal, or list

commonRuleLeftToRight :: Expr -> Expr Source

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.

commonRulesForSimplifyingExprs :: [Expr -> Expr] Source

A list of common rules for simplifying expressions. Does *not* include ruleIfRight, since that works for Haskell but not Python.

ruleRightToLeft :: Expr -> Expr Source

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)

applyFirstMatch :: [Expr -> Expr] -> Expr -> Expr Source

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.)

findFixed :: Eq a => (a -> a) -> a -> a Source

Repeatedly apply a function to an object until there is no change, that is, until reaching a fixed point of the function, a point where f x == x.