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)
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)
# 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)
# 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)