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)) ################### # MultitypeGraphs # ################### mysum = MultitypeGraph('mysum') @mysum.register(i64) def _mysum1(x): return x @mysum.register(i64, i64) def _mysum2(x, y): return x + y @mysum.register(i64, i64, i64) def _mysum3(x, y, z): return x + y + z
# ]) # def test_call_argument_higher_order(f): # def g(y): # return y + y # return f(g) @infer( (i64, i64, i64, i64), (f64, f64, f64, InferenceError), ) def test_multitype(x, y, z): return mysum(x) * mysum(x, y) * mysum(x, y, z) mystery = MultitypeGraph('mystery') @mystery.register(ai64, ai64) def _mystery1(x, y): return x @ y @mystery.register(af64, af64) def _mystery2(x, y): return array_map(scalar_add, x, y) @infer( (ai64_of(7, 9), ai64_of(9, 2), ai64_of(7, 2)), (af64_of(7, 9), af64_of(9, 2), InferenceError),
######## @dataclass(frozen=True) class Pair(ADT): """Common dataclass representing a pair.""" left: object right: object ################### # MultitypeGraphs # ################### mysum = MultitypeGraph("mysum") @mysum.register(i64) def _mysum1(x): return x @mysum.register(i64, i64) def _mysum2(x, y): return x + y @mysum.register(i64, i64, i64) def _mysum3(x, y, z): return x + y + z