Class: Dhall::TypeChecker::ToMap
- Inherits:
-
Object
- Object
- Dhall::TypeChecker::ToMap
- Defined in:
- lib/dhall/typecheck.rb
Instance Method Summary collapse
- #annotate(context) ⇒ Object
- #check_annotation(record_type) ⇒ Object
-
#initialize(tomap) ⇒ ToMap
constructor
A new instance of ToMap.
Constructor Details
#initialize(tomap) ⇒ ToMap
Returns a new instance of ToMap.
732 733 734 735 |
# File 'lib/dhall/typecheck.rb', line 732 def initialize(tomap) @tomap = tomap @record = TypeChecker.for(tomap.record) end |
Instance Method Details
#annotate(context) ⇒ Object
749 750 751 752 753 754 755 756 757 758 759 |
# File 'lib/dhall/typecheck.rb', line 749 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
737 738 739 740 741 742 743 744 745 746 747 |
# File 'lib/dhall/typecheck.rb', line 737 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 |