module Dhall::TypeChecker

Constants

BUILTIN_TYPES
KINDS

Public Class Methods

annotate(expr) click to toggle source
# File lib/dhall/typecheck.rb, line 45
def self.annotate(expr)
        return if expr.nil?
        TypeChecker.for(expr).annotate(TypeChecker::Context.new)
end
assert(type, assertion, message) click to toggle source
# File lib/dhall/typecheck.rb, line 8
def self.assert(type, assertion, message)
        raise TypeError, message unless assertion === type
        type
end
assert_type(expr, assertion, message, context:) click to toggle source
# File lib/dhall/typecheck.rb, line 13
def self.assert_type(expr, assertion, message, context:)
        aexpr = self.for(expr).annotate(context)
        type = aexpr.type.normalize
        raise TypeError, "#{message}: #{type}" unless assertion === type
        aexpr
end
assert_types_match(a, b, message, context:) click to toggle source
# File lib/dhall/typecheck.rb, line 20
def self.assert_types_match(a, b, message, context:)
        atype = self.for(a).annotate(context).type
        btype = self.for(b).annotate(context).type
        unless atype.normalize == btype.normalize
                raise TypeError, "#{message}: #{atype}, #{btype}"
        end
        atype
end
for(expr) click to toggle source
# File lib/dhall/typecheck.rb, line 29
def self.for(expr)
        @typecheckers.each do |node_matcher, (typechecker, extras)|
                if node_matcher === expr
                        msg = [:call, :for, :new].find { |m| typechecker.respond_to?(m) }
                        return typechecker.public_send(msg, expr, *extras)
                end
        end

        raise TypeError, "Unknown expression: #{expr.inspect}"
end
register(typechecker, node_type, *extras) click to toggle source
# File lib/dhall/typecheck.rb, line 40
def self.register(typechecker, node_type, *extras)
        @typecheckers ||= {}
        @typecheckers[node_type] ||= [typechecker, extras]
end
type_of(expr) click to toggle source
# File lib/dhall/typecheck.rb, line 50
def self.type_of(expr)
        annotate(expr)&.type
end