Class: Dhall::TypeChecker::Union

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

Instance Method Summary collapse

Constructor Details

#initialize(union) ⇒ Union

Returns a new instance of Union.



707
708
709
710
# File 'lib/dhall/typecheck.rb', line 707

def initialize(union)
	@union = union
	@value = TypeChecker.for(union.value)
end

Instance Method Details

#annotate(context) ⇒ Object



712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
# File 'lib/dhall/typecheck.rb', line 712

def annotate(context)
	annotated_value = @value.annotate(context)

	type = Dhall::UnionType.new(
		alternatives: { @union.tag => annotated_value.type }
	).merge(@union.alternatives)

	# Annotate to sanity check
	TypeChecker.for(type).annotate(context)

	Dhall::TypeAnnotation.new(
		value: @union.with(value: annotated_value),
		type:  type
	)
end