Skip to content

Instantly share code, notes, and snippets.

Created August 10, 2017 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/94d63f7f7aeff04180a30bca48d3199e to your computer and use it in GitHub Desktop.
Save anonymous/94d63f7f7aeff04180a30bca48d3199e to your computer and use it in GitHub Desktop.
the description for this gist
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