Last active
December 25, 2015 09:59
-
-
Save akimboyko/6958338 to your computer and use it in GitHub Desktop.
Quiz from Functional Programming Principles in Scala by Martin Odersky, lecture 4.2
This file contains 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
Provide an implementation of the abstract class Nat that represents non-negative integers | |
abstract class Nat { | |
def isZero: Boolean | |
def predecessor: Nat | |
def successor: Nat | |
def + (that: Nat): Nat | |
def - (that: Nat): Nat | |
} | |
Do not use standard numerical classes in this implementation. | |
Rather, implement a sub-object and sub-class: | |
object Zero extends Nat | |
class Succ(n: Nat) extends Nat | |
One of the number zero, then other for strictly positive numbers. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment