Class: Dhall::TypeChecker::Merge::Handlers

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

Instance Method Summary collapse

Constructor Details

#initialize(annotation) ⇒ Handlers

Returns a new instance of Handlers.



661
662
663
664
665
666
# File 'lib/dhall/typecheck.rb', line 661

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



684
685
686
687
688
689
690
691
692
# File 'lib/dhall/typecheck.rb', line 684

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

#keysObject



680
681
682
# File 'lib/dhall/typecheck.rb', line 680

def keys
  @type.record.keys
end

#output_type(output_annotation = nil) ⇒ Object



668
669
670
671
672
673
674
675
676
677
678
# File 'lib/dhall/typecheck.rb', line 668

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