Class: Dhall::TypeChecker::ToMap

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

Instance Method Summary collapse

Constructor Details

#initialize(tomap) ⇒ ToMap

Returns a new instance of ToMap.



692
693
694
695
# File 'lib/dhall/typecheck.rb', line 692

def initialize(tomap)
	@tomap = tomap
	@record = TypeChecker.for(tomap.record)
end

Instance Method Details

#annotate(context) ⇒ Object



709
710
711
712
713
714
715
716
717
718
719
# File 'lib/dhall/typecheck.rb', line 709

def annotate(context)
	record_type = @record.annotate(context).type
	TypeChecker.assert record_type, Dhall::RecordType,
	                   "toMap on a non-record: #{record_type.inspect}"

	TypeChecker.assert record_type.record.values, Util::ArrayAllTheSame,
	                   "toMap heterogenous: #{record_type.inspect}"

	type = check_annotation(record_type)
	Dhall::TypeAnnotation.new(value: @tomap, type: type)
end

#check_annotation(record_type) ⇒ Object



697
698
699
700
701
702
703
704
705
706
707
# File 'lib/dhall/typecheck.rb', line 697

def check_annotation(record_type)
	if record_type.is_a?(Dhall::EmptyRecordType)
		TypeChecker.assert @tomap.type, Dhall::Expression,
		                   "toMap {=} has no annotation"
	else
		t = Types::MAP(v: record_type.record.values.first)

		TypeChecker.assert t, (@tomap.type || t),
		                   "toMap does not match annotation"
	end
end