Created
February 5, 2019 19:22
-
-
Save Blaisorblade/23b9eae6df46bad3f551e51407c9286d to your computer and use it in GitHub Desktop.
Mutual dependencies across objects
This file contains 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
trait Eval { outer => | |
val t: Trees | |
val n: Normalize { val t: outer.t.type } | |
type Val | |
val eval: t.Exp => Val | |
val normalizingEval: t.Exp => Val = | |
exp => eval(n.normalize(exp)) | |
} | |
trait Normalize { outer => | |
val t: Trees | |
val e: Eval { val t: outer.t.type } | |
val reify: e.Val => t.Exp | |
val normalize: t.Exp => t.Exp = | |
exp => reify(e.eval(exp)) | |
} | |
class Interpreter { outer => | |
object t extends TreesImpl | |
object e extends EvalImpl { | |
val t = outer.t; val n = outer.n } | |
object n extends NormalizeImpl { | |
val t = outer.t; val e = outer.e } | |
} | |
object interpreter extends Interpreter | |
trait EvalImpl extends Eval { | |
val t: TreesImpl; import t._ | |
type Val = Int | |
val eval: Exp => Val = exp => exp match { | |
case Add(l, r) => eval(l) + eval(r) | |
case Lit(n) => n | |
} | |
} | |
trait NormalizeImpl extends Normalize { outer => | |
val t: TreesImpl | |
val e: EvalImpl { val t: outer.t.type } | |
val reify = t.Lit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment