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.
772 773 774 775 776 777 |
# File 'lib/dhall/typecheck.rb', line 772 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
795 796 797 798 799 800 801 802 803 |
# File 'lib/dhall/typecheck.rb', line 795 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
791 792 793 |
# File 'lib/dhall/typecheck.rb', line 791 def keys Set.new(@type.record.keys) end |
#output_type(output_annotation = nil) ⇒ Object
779 780 781 782 783 784 785 786 787 788 789 |
# File 'lib/dhall/typecheck.rb', line 779 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 |