open <*
bool: safetype ~ { t:[] },
num: safetype ~ { pred: num },
equal:
func[ [a:num,b:num] -> bool] ~
lambda x:[a:num,b:num]
in
if
x.a?pred => if x.b?pred => equal <a~x.a.pred,b~x.b.pred> else <> fi
else => if x.b?pred => <> else <t~<>> fi
fi
ni ,
plus:
func[ [a:num,b:num] -> num] ~
lambda x:[a:num,b:num]
in
if
x.a?pred => < pred ~ plus<a~x.a.pred,b~x.b>>
else => x.b
fi
ni ,
minus:
func[ [a:num,b:num] -> num] ~
lambda x:[a:num,b:num]
in
if
x.b?pred => if x.a?pred => minus <a~x.a.pred,b~x.b.pred> else zero<> fi
else => x.a
fi
ni ,
zero:
func[ []->num ] ~
lambda a:[] in <> ni ,
succ:
func[ a:num->num ] ~
lambda a:num in <pred~a> ni ,
pred:
func[ a:num->num ] ~
lambda a:num in if a?pred => a.pred else <> fi ni
*> in
open
ref[num]
in
open < n:loc~new<> >
in
assign< lhs~n, rhs~succ(zero<>) > ;
assign< lhs~n, rhs~plus< a~valOf n, b~valOf n >> ;
assign< lhs~n, rhs~plus< a~valOf n, b~valOf n >>
ni
ni
ni