class Dhall::TypeChecker::Merge::Handlers

Public Class Methods

new(annotation) click to toggle source
# File lib/dhall/typecheck.rb, line 772
def initialize(annotation)
        @type = annotation.type

        TypeChecker.assert @type, Dhall::RecordType,
                           "Merge expected Record got: #{@type}"
end

Public Instance Methods

fetch_input_type(k) click to toggle source
# 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() click to toggle source
# File lib/dhall/typecheck.rb, line 791
def keys
        Set.new(@type.record.keys)
end
output_type(output_annotation=nil) click to toggle source
# 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