Last active
December 15, 2015 08:09
-
-
Save chris-martin/5229048 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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