Safe Haskell | None |
---|---|
Language | Haskell98 |
- data Simplifier s a n
- = Trans (Transform s a n)
- | Seq (Simplifier s a n) (Simplifier s a n)
- | Fix Int (Simplifier s a n)
- data Transform s a n
- = Id
- | Anonymize
- | Beta Config
- | Bubble
- | Elaborate
- | Eta Config
- | Flatten
- | Forward
- | FoldCase Config
- | Inline {
- transInlineDef :: InlinerTemplates a n
- | Lambdas
- | Namify {
- transMkNamifierT :: Env n -> Namifier s n
- transMkNamifierX :: Env n -> Namifier s n
- | Prune
- | Rewrite {
- transRules :: NamedRewriteRules a n
- | Snip Config
- type InlinerTemplates a n = n -> Maybe (Exp a n)
- type NamedRewriteRules a n = [(String, RewriteRule a n)]
- data TransformResult r = TransformResult {
- result :: r
- resultProgress :: Bool
- resultAgain :: Bool
- resultInfo :: TransformInfo
- data TransformInfo = (Typeable i, Pretty i) => TransformInfo i
- resultDone :: String -> r -> TransformResult r
- applySimplifier :: (Show a, Pretty a, Ord n, Show n, Pretty n, CompoundName n) => Profile n -> KindEnv n -> TypeEnv n -> Simplifier s a n -> Module a n -> State s (TransformResult (Module a n))
- applySimplifierX :: (Show a, Pretty a, Show n, Ord n, Pretty n, CompoundName n) => Profile n -> KindEnv n -> TypeEnv n -> Simplifier s a n -> Exp a n -> State s (TransformResult (Exp a n))
Simplifier Specifications
data Simplifier s a n Source #
Specification of how to simplify a core program.
Trans (Transform s a n) | Apply a single transform. |
Seq (Simplifier s a n) (Simplifier s a n) | Apply two simplifiers in sequence. |
Fix Int (Simplifier s a n) | Keep applying a transform until it reports that further applications won't be helpful, bailing out after a maximum number of applications. |
Monoid (Simplifier s a n) Source # | |
Pretty (Simplifier s a n) Source # | |
Transform Specifications
Individual transforms to apply during simplification.
Id | The Identity transform returns the original program unharmed. |
Anonymize | Rewrite named binders to anonymous deBruijn binders. |
Beta Config | Perform beta reduction when the argument is not a redex. |
Bubble | Float casts outwards. |
Elaborate | Elaborate possible Const and Distinct witnesses that aren't otherwise in the program. |
Eta Config | Perform eta expansion and reduction. |
Flatten | Flatten nested let and case expressions. |
Forward | Float single-use bindings forward into their use sites. |
FoldCase Config | Fold case expressions. |
Inline | Inline definitions into their use sites. |
| |
Lambdas | Perform lambda lifting. |
Namify | Rewrite anonymous binders to fresh named binders. |
| |
Prune | Remove unused, pure let bindings. |
Rewrite | Apply general rule-based rewrites. |
| |
Snip Config | Introduce let-bindings for nested applications. |
type InlinerTemplates a n = n -> Maybe (Exp a n) Source #
Function to get the inliner template (unfolding) for the given name.
type NamedRewriteRules a n = [(String, RewriteRule a n)] Source #
Rewrite rules along with their names.
Transform Results
data TransformResult r Source #
Package up the result of applying a single transform.
TransformResult | |
|
Pretty (TransformResult r) Source # | |
data TransformInfo Source #
Existential package for a typeable thing,
used in TransformResult
.
(Typeable i, Pretty i) => TransformInfo i |
resultDone :: String -> r -> TransformResult r Source #
Create a default result with no transform again.
We'll say we made progress, but set resultAgain
to False
so to stop any simplifier fixpoints.
Application
:: (Show a, Pretty a, Ord n, Show n, Pretty n, CompoundName n) | |
=> Profile n | Profile of language we're working in |
-> KindEnv n | Kind environment |
-> TypeEnv n | Type environment |
-> Simplifier s a n | Simplifier to apply |
-> Module a n | Module to simplify |
-> State s (TransformResult (Module a n)) |
Apply a simplifier to a module.
The state monad can be used by Namifier
functions to generate fresh names.
:: (Show a, Pretty a, Show n, Ord n, Pretty n, CompoundName n) | |
=> Profile n | Profile of language we're working in |
-> KindEnv n | Kind environment |
-> TypeEnv n | Type environment |
-> Simplifier s a n | Simplifier to apply |
-> Exp a n | Expression to simplify |
-> State s (TransformResult (Exp a n)) |
Apply a simplifier to an expression.
The state monad can be used by Namifier
functions to generate fresh names.