Skip to content

Instantly share code, notes, and snippets.

/post.scala
Created Aug 10, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.