Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created December 11, 2015 00:54
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 workmad3/506b3cf8c1c1eb8188a8 to your computer and use it in GitHub Desktop.
Save workmad3/506b3cf8c1c1eb8188a8 to your computer and use it in GitHub Desktop.
class True
class << self
def true?
self
end
def !@
False
end
def &(other)
other.true?
end
def |(other)
self
end
def inspect
"True"
end
end
end
class False
class << self
def !@
True
end
def &(other)
self
end
def |(other)
other.true?
end
def true?
self
end
def inspect
"False"
end
end
end
class SBottom
def zero?
False
end
def greater_than_or_equal_to_zero?
False
end
def ==(other)
False
end
end
class Zero
def zero?
True
end
def greater_than_or_equal_to_zero?
True
end
def succ
S(self)
end
def pred
SBottom.new
end
def inspect
"0"
end
def +(other)
other
end
def *(other)
self
end
def ==(other)
other.zero?
end
def <=(other)
other.greater_than_or_equal_to_zero?
end
def <(other)
self.succ <= other
end
end
class S
def initialize(pred)
@pred = pred
end
def pred
@pred
end
def succ
S(self)
end
def zero?
False
end
def greater_than_or_equal_to_zero?
True
end
def ==(other)
pred == other.pred
end
def +(other)
pred + other.succ
end
def *(other)
self + (other.pred * self)
end
def <=(other)
self.pred <= other.pred
end
def <(other)
self.succ <= other
end
def inspect
"S(#{pred.inspect})"
end
end
def S(s)
S.new(s)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment