Skip to content

Instantly share code, notes, and snippets.

@yilinwei
Created June 10, 2017 15:06
Show Gist options
  • Save yilinwei/b2483fbf4b28b1a302169c86f73ca1ea to your computer and use it in GitHub Desktop.
Save yilinwei/b2483fbf4b28b1a302169c86f73ca1ea to your computer and use it in GitHub Desktop.
problem.scala
val show: Algebra[SExp, Option[String] => String] = {
case True => _ => "t"
case Symbol(s) => _ => s"'$s"
case Keyword(k) => _ => s":$k"
case Char(c) => _ => s"?$c"
case Int(v) => _ => v.toString
case Nil => {
case None => "nil"
case Some(p) => s"$p)"
}
case Pair(l, r) => {
case None => r(Some(s"(${l(None)}"))
case Some(p) => r(Some(s"$p ${l(None) }"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment