コード例 #1
0
def exp_typ_in(exp, se, bindings=None):
    global __functs__
    if bindings == None:
        bindings = {}
    if atomp(exp):
        if se == exp:
            return Typ.create(T_ENTITY)  # TODO truth literal?
        else:
            return None
    elif lambdap(exp):
        # t = Typ.create_from_string(lambda_arg_typ(exp))
        t = lambda_arg_typ(exp)
        if isinstance(t, str):
            t = Typ.create(t)
        if se == lambda_arg_name(exp):
            return t
        elif se == exp:
            bindings[lambda_arg_name(exp)] = t
            # return Typ.product([t, exp_typ_in(lambda_body(exp), lambda_body(exp),
            # bindings)])
            r = exp_typ_in(lambda_body(exp), lambda_body(exp), bindings)
            return Typ.product([t, r])
        else:
            bindings[lambda_arg_name(exp)] = t
            return exp_typ_in(lambda_body(exp), se, bindings)
    elif quantifierp(exp):
        # t = __functs__[application_function(exp)][0]
        t = Typ.create(T_ENTITY)  # TODO doesn't need to be manual
        if se == quantifier_var(exp):
            return t
        elif se == exp:
            return Typ.return_typ(__functs__[application_function(exp)])
        else:
            bindings[quantifier_var(exp)] = t
            for i in range(2, 2 + len(quantifier_args(exp))):
                r = exp_typ_in(exp[i], se, bindings)
                if not (r == None):
                    return r
            return None
    elif applicationp(exp):
        if se == exp:
            if application_function(exp) in bindings:
                return Typ.return_typ(bindings[application_function(exp)])
            else:
                return Typ.return_typ(__functs__[application_function(exp)])
        else:
            for i in range(1, 1 + len(application_args(exp))):
                r = exp_typ_in(exp[i], se, bindings)
                if not (r == None):
                    return r
            # print "couldn't get %s from %s" % (se, exp)
            # assert False
            return None
コード例 #2
0
def application_typ(sexp):

    # print sexp

    funct_typ = typ(application_function(sexp))
    # the arg signature might be any combination of the signatures of each arg
    arg_typ = Typ.product([typ(arg) for arg in application_args(sexp)])

    # assert functp(application_function(sexp))

    funct_arg_typ = Typ.arg_typ(funct_typ)
    funct_return_typ = Typ.return_typ(funct_typ)

    print sexp
    print "function expects", funct_arg_typ
    print "actual args", application_args(sexp)
    print "arg_typ", arg_typ

    # assert Typ.check_equivalence(arg_typ, funct_arg_typ)
    # TODO doesn't handle functions properly
    return funct_return_typ