class Dhallish::Ast::FunctionType

Attributes

lhs[RW]
rhs[RW]
type_var[RW]

Public Class Methods

new(lhs, rhs, type_var=nil) click to toggle source

lhs and rhs should be values of type Type if Function Type contains “forall” , e.g. “forall(t : Type) -> Natural”, type_var should contain the introduced label as a string otherwise, type_var shall be nil

# File lib/ast.rb, line 571
def initialize(lhs, rhs, type_var=nil)
        @lhs = lhs
        @rhs = rhs
        @type_var = type_var
end

Public Instance Methods

compute_type(ctx) click to toggle source
# File lib/ast.rb, line 577
def compute_type(ctx)
        lhs_type = @lhs.compute_type ctx
        assert ("Expression for argument type not a type") { lhs_type.is_a? Types::Type }
        lhs_type = lhs_type.metadata
        new_ctx = ctx
        type_var = nil
        if !@type_var.nil? and lhs_type.is_a? Types::Type
                new_ctx = Context.new ctx
                lhs_type = new_ctx[@type_var] = Types::Type.new (Types::Unresolved.new @type_var)
                type_var = @type_var
        end
        rhs_type = @rhs.compute_type new_ctx
        assert ("Expression for result type not a type") { rhs_type.is_a? Types::Type }
        rhs_type = rhs_type.metadata
        Types::Type.new (Types::Function.new lhs_type, rhs_type, type_var)
end
evaluate(ctx) click to toggle source
# File lib/ast.rb, line 594
def evaluate(ctx)
        lhs = @lhs.evaluate(ctx)

        if !type_var.nil? and lhs.is_a? Types::Type
                new_ctx = Context.new(ctx)
                new_ctx[type_var] = Types::Unresolved.new(type_var)
                rhs = @rhs.evaluate(new_ctx)
        else
                rhs = @rhs.evaluate(ctx)
        end

        Types::Function.new(lhs, rhs, type_var)
end