Skip to content

Commit

Permalink
progfunsamples
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco Tanudjaja committed Aug 21, 2017
1 parent 5613773 commit f38f11b
Show file tree
Hide file tree
Showing 18 changed files with 3,296 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/mooc/progfunsamples/Expr.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package week4

trait Expr {
def isNumber: Boolean
def isSum: Boolean
def numValue: Int
def leftOp: Expr
def rightOp: Expr
}
class Number(n: Int) extends Expr {
def isNumber: Boolean = true
def isSum: Boolean = false
def numValue: Int = n
def leftOp: Expr = throw new Error("Number.leftOp")
def rightOp: Expr = throw new Error("Number.rightOp")
}

class Sum(e1: Expr, e2: Expr) extends Expr {
def isNumber: Boolean = false
def isSum: Boolean = true
def numValue: Int = throw new Error("Sum.numValue")
def leftOp: Expr = e1
def rightOp: Expr = e2
}

Loading

0 comments on commit f38f11b

Please sign in to comment.