Example #1
0
def test_union_nested(x, y):
    if hastype(x, i64):
        return x
    elif hastype(x, f64):
        return y
    else:
        return x[0]
Example #2
0
def test_union_nested_2(x):
    if hastype(x, i64):
        return x
    elif hastype(x, f64):
        return 1234
    else:
        return x[0]
Example #3
0
def test_hastype_interference(x, y, z):
    if hastype(1, i32):
        return x
    elif hastype(1, i64):
        return y
    else:
        return z
Example #4
0
def sumtree(t):
    if hastype(t, Number):
        return t
    elif hastype(t, Nil):
        return 0
    else:
        return sumtree(t.left) + sumtree(t.right)
Example #5
0
 def helper(x):
     if hastype(x, i64):
         return x
     elif hastype(x, f64):
         return x
     else:
         return (x, )
Example #6
0
def reducetree(fn, t, init):
    if hastype(t, Number):
        return t
    elif hastype(t, Nil):
        return init
    else:
        return fn(reducetree(fn, t.left, init), reducetree(fn, t.right, init))
Example #7
0
def test_union_nested_2(x, y):
    if hastype(x, Number):
        if hastype(x, i64):
            return x
        else:
            return y
    else:
        return x[0]
Example #8
0
def test_prim_ismyiatype():
    i64 = Int[64]
    f64 = Float[64]
    assert hastype(123, i64)
    assert not hastype(123.4, i64)
    assert hastype(123.4, f64)
    assert hastype([1, 2, 3], List)
    assert hastype([1, 2, 3], List[i64])
    assert hastype((1, 2.0, (3, 4)), Tuple)
    assert hastype((1, 2.0, (3, 4)), Tuple[i64, f64, Tuple[i64, i64]])
    with pytest.raises(TypeError):
        hastype([1, 2, 3.4], List)
    assert hastype(object(), External[object])
Example #9
0
 def f(x):
     if hastype(x, i64):
         return x
     elif hastype(x, f64):
         return f(_to_i64(x))
     elif hastype(x, ai64):
         return 0.0
     elif hastype(x, Point):
         return f(x.x) * f(x.y)
     elif hastype(x, EmptyTuple):
         return 0
     elif hastype(x, Tf4):
         return x
     elif hastype(x, Tuple):
         return f(x[0]) + f(x[1:])
     elif hastype(x, List):
         return 1.0
     elif hastype(x, Thing_ftup):
         return x.contents
     else:
         return 0
Example #10
0
 def f(x):
     if hastype(x, i64):
         return x
     elif hastype(x, f64):
         return f(_to_i64(x))
     elif hastype(x, ai64):
         return 0.0
     elif hastype(x, Point_t):
         return f(x.x) * f(x.y)
     elif hastype(x, Nil):
         return 0
     elif hastype(x, Tf4):
         return x
     elif hastype(x, T):
         return f(x[0]) + f(tail(x))
     elif hastype(x, L):
         return 1.0
     elif hastype(x, Thing_ftup):
         return x.contents
     else:
         return 0
Example #11
0
def test_user_switch_hastype(x, y):
    return user_switch(hastype(x, i64), y + 1, y + 2)
Example #12
0
def test_hastype_simple(x):
    return hastype(x, i64)
Example #13
0
def test_hastype(x, y):
    return hastype(x, y)
Example #14
0
def test_union(x):
    if hastype(x, i64):
        return x
    else:
        return x[0]
Example #15
0
def _interference_helper(x):
    if hastype(x, T):
        return x[0]
    else:
        return x
Example #16
0
 def condition(x):
     return hastype(x, i64) and x > 0
Example #17
0
def test_union(x):
    if hastype(x, f64):
        return x * x * x
    else:
        a, b = x
        return a * b
Example #18
0
def test_raise_hastype(x):
    if hastype(x, i32):
        raise Exception("What a terrible type")
    else:
        return x