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.



220
221
222
223
224
225
# File 'lib/dhall/typecheck.rb', line 220

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



227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/dhall/typecheck.rb', line 227

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