Class: Dhall::TypeChecker::Context
- Inherits:
-
Object
- Object
- Dhall::TypeChecker::Context
- Defined in:
- lib/dhall/typecheck.rb
Instance Method Summary collapse
- #add(ftype) ⇒ Object
- #fetch(var) ⇒ Object
-
#initialize(bindings = Hash.new([])) ⇒ Context
constructor
A new instance of Context.
- #shift(amount, name, min_index) ⇒ Object
Constructor Details
#initialize(bindings = Hash.new([])) ⇒ Context
Returns a new instance of Context.
49 50 51 52 |
# File 'lib/dhall/typecheck.rb', line 49 def initialize(bindings=Hash.new([])) @bindings = bindings.freeze freeze end |
Instance Method Details
#add(ftype) ⇒ Object
59 60 61 62 63 |
# File 'lib/dhall/typecheck.rb', line 59 def add(ftype) self.class.new(@bindings.merge( ftype.var => [ftype.type] + @bindings[ftype.var] )).shift(1, ftype.var, 0) end |
#fetch(var) ⇒ Object
54 55 56 57 |
# File 'lib/dhall/typecheck.rb', line 54 def fetch(var) @bindings[var.name][var.index] || (raise TypeError, "Free variable: #{var}") end |
#shift(amount, name, min_index) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/dhall/typecheck.rb', line 65 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 |