示例#1
0
文件: nat.py 项目: xchani/tvm
def define_nat_adt(prelude):
    """Defines a Peano (unary) natural number ADT.
    Zero is represented by z(). s(n) adds 1 to a nat n.
    Adds the fields nat, z, and s to the preluide, representing
    (respectively) the nat ADT and the z and s constructors.
    """
    prelude.nat = GlobalTypeVar("nat")
    prelude.z = Constructor("z", [], prelude.nat)
    prelude.s = Constructor("s", [prelude.nat()], prelude.nat)
    prelude.mod[prelude.nat] = TypeData(prelude.nat, [], [prelude.z, prelude.s])
def test_type_call():
    tc = TypeCall(GlobalTypeVar("tf"), [TupleType([])])
    check_visit(tc)
def test_type_data():
    td = TypeData(GlobalTypeVar("td"), [TypeVar("tv")], [])
    check_visit(td)
def test_global_type_var():
    gtv = GlobalTypeVar("gtv")
    check_visit(gtv)
示例#5
0
def test_type_data():
    td = TypeData(GlobalTypeVar('td'), [TypeVar('tv')], [])
    check_visit(td)