Last active
March 6, 2017 22:12
-
-
Save paulp/c9065356441cdc2632e8d62adb85e302 to your computer and use it in GitHub Desktop.
matryoshka
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*** v *** *** vopt *** *** vsub *** *** voptsub *** | |
'x := 'x := <?> <?> | |
| | | | | |
+- 3 +- 3 +- <?> +- 10 | |
| | | | | | |
`- <?> `- <?> | +- 2 `- <?> | |
| | | | | | |
+- <?> +- 10 | `- 3 +- 3 | |
| | | | | | |
| +- 2 `- <?> `- <?> `- 3 | |
| | | | | |
| `- 'x +- 'x +- 5 | |
| | | | |
`- <?> `- 'x `- 3 | |
| | |
+- 5 | |
| | |
`- 'x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val v = let('x, 3, mul(mul(2, 'x), mul(5, 'x))) | |
val vopt = v.cata[Fix[Exp]] { | |
case Mul(Embed(LinearTerm(n1, v1)), Embed(LinearTerm(n2, v2))) if v1 == v2 => mul(n1 * n2, mul(v1, v1)) | |
case x => x.embed | |
} | |
val vsub = v.topDownCata(noVars[Fix])(subst) | |
val voptsub = vopt.topDownCata(noVars[Fix])(subst) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment