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/5accc12d5d05594adc086716fbb2258c to your computer and use it in GitHub Desktop.
Save anonymous/5accc12d5d05594adc086716fbb2258c to your computer and use it in GitHub Desktop.
the description for this gist
type PrettyPrint[ScalaValue] = String
val interpretAsPrettyPrint = new Language[PrettyPrint] {
override def number(v: Int): PrettyPrint[Int] = s"($v)"
override def increment(a: PrettyPrint[Int]): PrettyPrint[Int] = s"(inc $a)"
override def add(a: PrettyPrint[Int], b: PrettyPrint[Int]): PrettyPrint[Int] = s"(+ $a $b)"
override def text(v: String): PrettyPrint[String] = s"[$v]"
override def toUpper(a: PrettyPrint[String]): PrettyPrint[String] = s"(toUpper $a)"
override def concat(a: PrettyPrint[String], b: PrettyPrint[String]): PrettyPrint[String] = s"(concat $a $b)"
override def toString(v: PrettyPrint[Int]): PrettyPrint[String] = s"(toString $v)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment