Esempio n. 1
0
def app_expr(f, f_ty, cast, args):
    """Applies a function to a list of
    arguments, some of which are implicit.
    
    Arguments:
    - `f`: an expression denoting the function
    - `f_ty`: the function type
    - `cast`: list of evidence terms for the type conversions
    of each argument
    - `args`: a list of arguments
    """
    tm = f
    rem_args = args
    rem_cast = cast
    rem_ty = f_ty

    #TODO: This is a bit of a hack. We need "maximally inserted arguments"
    #as in Coq to do this cleanly
    if len(args) == 0:
        while rem_ty.is_pi()\
              and rem_ty.info.implicit:
            mvar = mk_meta(rem_ty.binder.var, rem_ty.dom)
            #At this point we give the trivial evidence.
            #after the term is created, we go through the whole
            #term to collect local information (variables) and to add them
            #the evidence term
            mcast = trivial()
            tm = t.App(mcast, tm, mvar)
            rem_ty = e.subst_expr([mvar], rem_ty.body)
    else:
        while len(rem_args) != 0:
            if rem_ty.is_pi()\
               and rem_ty.info.implicit:
                mvar = mk_meta(rem_ty.binder.var, rem_ty.dom)
                mcast = trivial()
                tm = t.App(mcast, tm, mvar)
                rem_ty = e.subst_expr([mvar], rem_ty.body)
            elif rem_ty.is_pi():
                tm = t.App(rem_cast[0], tm, rem_args[0])
                rem_ty = e.subst_expr([rem_args[0]], rem_ty.body)
                rem_cast = rem_cast[1:]
                rem_args = rem_args[1:]
            else:
                #In this case, something is wrong with the type
                #of f, and we simply blindly apply all the remaining
                #arguments.
                tm = t.App(rem_cast[0], tm, rem_args[0])
                rem_cast = rem_cast[1:]
                rem_args = rem_args[1:]
    return tm
Esempio n. 2
0
def app_expr(f, f_ty, cast, args):
    """Applies a function to a list of
    arguments, some of which are implicit.
    
    Arguments:
    - `f`: an expression denoting the function
    - `f_ty`: the function type
    - `cast`: list of evidence terms for the type conversions
    of each argument
    - `args`: a list of arguments
    """
    tm = f
    rem_args = args
    rem_cast = cast
    rem_ty = f_ty

    #TODO: This is a bit of a hack. We need "maximally inserted arguments"
    #as in Coq to do this cleanly
    if len(args) == 0:
        while rem_ty.is_pi()\
              and rem_ty.info.implicit:
            mvar = mk_meta(rem_ty.binder.var, rem_ty.dom)
            #At this point we give the trivial evidence.
            #after the term is created, we go through the whole
            #term to collect local information (variables) and to add them
            #the evidence term
            mcast = trivial()
            tm = t.App(mcast, tm, mvar)
            rem_ty = e.subst_expr([mvar], rem_ty.body)
    else:
        while len(rem_args) != 0:
            if rem_ty.is_pi()\
               and rem_ty.info.implicit:
                mvar = mk_meta(rem_ty.binder.var, rem_ty.dom)
                mcast = trivial()
                tm = t.App(mcast, tm, mvar)
                rem_ty = e.subst_expr([mvar], rem_ty.body)
            elif rem_ty.is_pi():
                tm = t.App(rem_cast[0], tm, rem_args[0])
                rem_ty = e.subst_expr([rem_args[0]], rem_ty.body)
                rem_cast = rem_cast[1:]
                rem_args = rem_args[1:]
            else:
                #In this case, something is wrong with the type
                #of f, and we simply blindly apply all the remaining
                #arguments.
                tm = t.App(rem_cast[0], tm, rem_args[0])
                rem_cast = rem_cast[1:]
                rem_args = rem_args[1:]
    return tm
Esempio n. 3
0
def instantiate_bound_expr(e1, e2):
    """Takes an expression e1 of the form  'Binder dom, body', and returns
    the result of substituting e2 in body.
    """
    assert (e1.is_bound())
    return subst_expr([e2], e1.body)
Esempio n. 4
0
def instantiate_bound_expr(e1, e2):
    """Takes an expression e1 of the form  'Binder dom, body', and returns
    the result of substituting e2 in body.
    """
    assert(e1.is_bound())
    return subst_expr([e2], e1.body)
Esempio n. 5
0
def mvar_open_expr(var, typ, expr):
    mvar = e.Mvar(var, typ)
    return e.subst_expr([mvar], expr)
Esempio n. 6
0
def mvar_open_expr(var, typ, expr):
    mvar = e.Mvar(var, typ)
    return e.subst_expr([mvar], expr)