def lift(arg, ltype): larg_type = types.FunType(arg.type, ltype) combinator = meta.LFun( arg.type, meta.LFun(larg_type, meta.term("g", larg_type)(meta.term("f", arg.type)), "g"), "f") result = combinator(arg).reduce_all() return result
def z_combinator_fun(ftype): # does not check types... left_type = ftype.left g_type = types.FunType(types.type_e, left_type) body = meta.term("f", ftype)(meta.term("g", g_type)(meta.term( "x", types.type_e)))(meta.term("x", types.type_e)) comb = meta.LFun(ftype, meta.LFun(g_type, meta.LFun(types.type_e, body, varname="x"), varname="g"), varname="f") return comb
def continuize_app_combinator2(ftype, argtype): try: b = ftype.left.left except: raise types.TypeMismatch(ftype, None, "Not a continuation type") try: abar = types.FunType(b.right, types.type_t) except: raise types.TypeMismatch(ftype, None, "Not a continuized function type") try: c = argtype.left.left except: raise types.TypeMismatch(argtype, None, "Not a continuation type") comb_s = ( "L f_%s : L arg_%s : L abar_%s : arg(L c_%s : f(L b_%s : abar(b(c))))" % (repr(ftype), repr(argtype), repr(abar), repr(c), repr(b))) comb = te(comb_s) return comb
def continuize_app_combinator(ftype, argtype): try: b = ftype.left.left except: # note that exceptions other than TypeMismatch will halt # composition; a TypeMismatch just signals that a particular attempt # won't succeed. raise types.TypeMismatch(ftype, None, "Not a continuized function type") try: abar = types.FunType(b.right, types.type_t) except: raise types.TypeMismatch(ftype, None, "Not a continuized function type") try: c = argtype.left.left except: raise types.TypeMismatch(argtype, None, "Not a continuation type") comb_s = ( "L f_%s : L arg_%s : L abar_%s : f(L b_%s : arg(L c_%s : abar(b(c))))" % (repr(ftype), repr(argtype), repr(abar), repr(b), repr(c))) comb = te(comb_s) # parse the combinator string return comb
def geach_shift(fun, f_type_left): combinator = geach_combinator(fun.type, types.FunType(f_type_left, fun.type.left)) return combinator(fun).reduce_all()
def continuize_combinator_fun(typ): cont_type = types.FunType(typ, types.type_t) comb = lang.te("L x_%s : L f_%s : f(x)" % (repr(typ), repr(cont_type))) return comb