Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Last active December 15, 2015 08:09
Show Gist options
  • Save chris-martin/5229048 to your computer and use it in GitHub Desktop.
Save chris-martin/5229048 to your computer and use it in GitHub Desktop.
sealed trait Sigma
case class Lit(s: String) extends Sigma
case class Concat(s: Sigma, t: Sigma) extends Sigma
case class Ext extends Sigma
def eval1(sig: Sigma): Sigma = sig match {
case Concat(s, t) => {
val Lit(e1) = eval1(s)
val Lit(e2) = eval1(s)
Lit(e1 + e2)
}
case Ext => Lit(readLine)
case x => x
}
def eval2(sig: Sigma, stdin: String): Sigma = sig match {
case Concat(s, t) => {
val Lit(e1) = eval2(s)
val Lit(e2) = eval2(s)
Lit(e1 + e2)
}
case Ext => Lit(stdin)
case x => x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment