Class: Dhall::TypeChecker::Merge::Handlers
- Inherits:
-
Object
- Object
- Dhall::TypeChecker::Merge::Handlers
- Defined in:
- lib/dhall/typecheck.rb
Instance Method Summary collapse
- #fetch_input_type(k) ⇒ Object
-
#initialize(annotation) ⇒ Handlers
constructor
A new instance of Handlers.
- #keys ⇒ Object
- #output_type(output_annotation = nil) ⇒ Object
Constructor Details
#initialize(annotation) ⇒ Handlers
Returns a new instance of Handlers.
732 733 734 735 736 737 |
# File 'lib/dhall/typecheck.rb', line 732 def initialize(annotation) @type = annotation.type TypeChecker.assert @type, Dhall::RecordType, "Merge expected Record got: #{@type}" end |
Instance Method Details
#fetch_input_type(k) ⇒ Object
755 756 757 758 759 760 761 762 763 |
# File 'lib/dhall/typecheck.rb', line 755 def fetch_input_type(k) type = @type.record.fetch(k) do raise TypeError, "No merge handler for alternative: #{k}" end TypeChecker.assert type, Dhall::Forall, "Handler is not a function" type.type end |
#keys ⇒ Object
751 752 753 |
# File 'lib/dhall/typecheck.rb', line 751 def keys @type.record.keys end |
#output_type(output_annotation = nil) ⇒ Object
739 740 741 742 743 744 745 746 747 748 749 |
# File 'lib/dhall/typecheck.rb', line 739 def output_type(output_annotation=nil) @type.record.values.reduce(output_annotation) do |type_acc, htype| htype = htype.body.shift(-1, htype.var, 0) if htype.is_a?(Dhall::Forall) if type_acc && htype.normalize != type_acc.normalize raise TypeError, "Handler output types must all match" end htype end end |