Пример #1
0
        return '?'

def unify(a,b):
    """
    Very simple unification.
    """

    if (a,b) == (int, int):
        return int

    if (a,b) == (int, float):
        return float

    if (a,b) == (float, int):
        return float

    raise Incommensurable(a,b)

#------------------------------------------------------------------------
# Type System
#------------------------------------------------------------------------

PythonT = typesystem(unifier=unify, top=object, dynamic=dynamic, typeof=type)

#------------------------------------------------------------------------
# Tests
#------------------------------------------------------------------------

def test_simple_uni():
    res = infer('a -> a', [1], {'a': ints}, PythonT)
Пример #2
0
def unify(a, b):
    """
    Very simple unification.
    """

    if (a, b) == (int, int):
        return int

    if (a, b) == (int, float):
        return float

    if (a, b) == (float, int):
        return float

    raise Incommensurable(a, b)


#------------------------------------------------------------------------
# Type System
#------------------------------------------------------------------------

PythonT = typesystem(unifier=unify, top=object, dynamic=dynamic, typeof=type)

#------------------------------------------------------------------------
# Tests
#------------------------------------------------------------------------


def test_simple_uni():
    res = infer('a -> a', [1], {'a': ints}, PythonT)
Пример #3
0
# Blaze Typesystem
# ------------------------------------------------------------------------

# unify   : the type unification function
# top     : the top type
# dynamic : the dynamic type
# typeof  : the value deconstructor

# Judgements over a type system are uniquely defined by three things:
#
# * a type unifier
# * a top type
# * a value deconstructor
# * universe of first order terms

BlazeT = typesystem(unify, top, any, typeof)

# ------------------------------------------------------------------------
# Graph Construction
# ------------------------------------------------------------------------


def is_homogeneous(it):
    # Checks Python types for arguments, not to be confused with the
    # datashape types and the operator types!

    head = it[0]
    head_type = type(head)
    return head, all(type(a) == head_type for a in it)

Пример #4
0
# Blaze Typesystem
#------------------------------------------------------------------------

# unify   : the type unification function
# top     : the top type
# dynamic : the dynamic type
# typeof  : the value deconstructor

# Judgements over a type system are uniquely defined by three things:
#
# * a type unifier
# * a top type
# * a value deconstructor
# * universe of first order terms

BlazeT = typesystem(unify, top, any, typeof)

#------------------------------------------------------------------------
# Graph Construction
#------------------------------------------------------------------------


def is_homogeneous(it):
    # Checks Python types for arguments, not to be confused with the
    # datashape types and the operator types!

    head = it[0]
    head_type = type(head)
    return head, all(type(a) == head_type for a in it)