Exemple #1
0
def sig(var, codom):
    """Create the term
    Sig x:A.B from its constituents
    
    Arguments:
    - `var`: a constant expr
    - `codom`: an expression possibly containing var
    """
    if var.is_const():
        codom_abs = e.abstract_expr([var.name], codom)
        return e.Bound(e.Sig(var.name), var.type, codom_abs)
    else:
        mess = "Expected {0!s} to be a constant".format(var)
        raise e.ExprError(mess, var)
Exemple #2
0
def exists(var, prop):
    """Create the term
    exists x:A.t from its constituents
    
    Arguments:
    - `var`: a constant expr
    - `prop`: an expression possibly containing var
    """
    if var.is_const():
        prop_abs = e.abstract_expr([var.name], prop)
        return e.Bound(e.Exists(var.name), var.type, prop_abs)
    else:
        mess = "Expected {0!s} to be a constant".format(var)
        raise e.ExprError(mess, var)
Exemple #3
0
def pi(var, codom, impl=None):
    """Create the term
    Pi x:A.B from its constituents
    
    Arguments:
    - `var`: a constant expr
    - `codom`: an expression possibly containing var
    - `impl`: a flag which notes if the argument is implicit.
    """
    if var.is_const():
        codom_abs = e.abstract_expr([var.name], codom)
        ret = e.Bound(e.Pi(var.name), var.type, codom_abs)
        if impl:
            ret.info['implicit'] = True
        return ret
    else:
        mess = "Expected {0!s} to be a constant".format(var)
        raise e.ExprError(mess, var)
Exemple #4
0
def abst(var, body):
    """Create the term
    lambda x:A.t from its constituents
    
    Arguments:
    - `var`: a constant expr
    - `body`: an expression possibly containing var
    """
    if var.is_const():
        ty, _ = mvar_infer(var.type)
        if ty.equals(e.Bool()):
            body = enrich(var.name, var.type, body)
        else:
            pass
        body_abs = e.abstract_expr([var.name], body)
        return e.Bound(e.Abst(var.name), var.type, body_abs)
    else:
        print var.__class__
        mess = "Expected {0!s} to be a constant".format(var)
        raise e.ExprError(mess, var)
Exemple #5
0
 def visit_bound(self, expr, *args, **kwargs):
     var, open_expr = self.open_fresh(expr)
     new_open_expr = self.visit(open_expr)
     dom = self.visit(expr.dom)
     return e.Bound(expr.binder, dom, self.abst([var], new_open_expr))
Exemple #6
0
 def visit_bound(self, expr):
     dom = self.visit(expr.dom)
     body = self.visit(expr.body)
     return e.Bound(expr.binder, dom, body)