Class: Dhall::TypeChecker::Operator

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

Instance Method Summary collapse

Constructor Details

#initialize(expr, type) ⇒ Operator

Returns a new instance of Operator.



214
215
216
217
218
219
# File 'lib/dhall/typecheck.rb', line 214

def initialize(expr, type)
  @expr = expr
  @lhs = TypeChecker.for(expr.lhs)
  @rhs = TypeChecker.for(expr.rhs)
  @type = type
end

Instance Method Details

#annotate(context) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/dhall/typecheck.rb', line 221

def annotate(context)
  annotated_lhs = @lhs.annotate(context)
  annotated_rhs = @rhs.annotate(context)
  types = [annotated_lhs.type, annotated_rhs.type]
  if types.any? { |t| t != @type }
    raise TypeError, "Operator arguments not #{@type}: #{types}"
  end

  Dhall::TypeAnnotation.new(
    value: @expr.with(lhs: annotated_lhs, rhs: annotated_rhs),
    type:  @type
  )
end