Created
August 10, 2017 06:32
-
-
Save anonymous/94d63f7f7aeff04180a30bca48d3199e to your computer and use it in GitHub Desktop.
the description for this gist
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
type Nested[ScalaValue] = ScalaToLanguageBridge[ScalaValue] | |
val simplify = new Language[Nested]{ | |
var nesting = 0 | |
override def number(v: Int): Nested[Int] = new ScalaToLanguageBridge[Int] { | |
override def apply[Wrapper[_]](implicit L: Language[Wrapper]): Wrapper[Int] = { | |
if(nesting > 0) { | |
val temp = nesting | |
nesting = 0 | |
L.add(L.number(temp), L.number(v)) | |
} else { | |
L.number(v) | |
} | |
} | |
} | |
override def increment(a: ScalaToLanguageBridge[Int]): Nested[Int] = new ScalaToLanguageBridge[Int] { | |
override def apply[Wrapper[_]](implicit L: Language[Wrapper]): Wrapper[Int] = { | |
nesting = nesting + 1 | |
a.apply(L) | |
} | |
} | |
override def add(a: ScalaToLanguageBridge[Int], b: ScalaToLanguageBridge[Int]): Nested[Int] = new ScalaToLanguageBridge[Int] { | |
override def apply[Wrapper[_]](implicit L: Language[Wrapper]): Wrapper[Int] = { | |
if(nesting > 0){ | |
val temp = nesting | |
nesting = 0 | |
L.add(L.number(temp), L.add(a.apply(L), b.apply(L))) | |
} else { | |
L.add(a.apply(L), b.apply(L)) | |
} | |
} | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment