Skip to content

Instantly share code, notes, and snippets.

@akimboyko
Last active December 25, 2015 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akimboyko/6958338 to your computer and use it in GitHub Desktop.
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
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