Class: Dhall::TypeChecker::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/dhall/typecheck.rb

Instance Method Summary collapse

Constructor Details

#initialize(bindings = Hash.new([])) ⇒ Context

Returns a new instance of Context.



53
54
55
56
# File 'lib/dhall/typecheck.rb', line 53

def initialize(bindings=Hash.new([]))
	@bindings = bindings.freeze
	freeze
end

Instance Method Details

#add(ftype) ⇒ Object



63
64
65
66
67
# File 'lib/dhall/typecheck.rb', line 63

def add(ftype)
	self.class.new(@bindings.merge(
		ftype.var => [ftype.type] + @bindings[ftype.var]
	)).shift(1, ftype.var, 0)
end

#fetch(var) ⇒ Object



58
59
60
61
# File 'lib/dhall/typecheck.rb', line 58

def fetch(var)
	@bindings[var.name][var.index] ||
		(raise TypeError, "Free variable: #{var}")
end

#shift(amount, name, min_index) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/dhall/typecheck.rb', line 69

def shift(amount, name, min_index)
	self.class.new(@bindings.merge(
		Hash[@bindings.map do |var, bindings|
			[var, bindings.map { |b| b.shift(amount, name, min_index) }]
		end]
	))
end