% $Id: Naturals.oz,v 1.1 2007/10/22 05:23:42 leavens Exp leavens $ % Natural numbers, encoded as: % ::= zero | succ ( ) declare % Return the Natural corresponding to I fun {FromInteger I} if I =< 0 then zero else succ({FromInteger I-1}) end end % Return the Int corresponding to N fun {ToInteger N} case N of zero then 0 [] succ(P) then 1 + {ToInteger P} end end % Return the Natural that represents the sum of N1 and N2 fun {Plus N1 N2} case N1 of zero then N2 [] succ(P) then succ({Plus P N2}) end end % Is N zero? fun {IsZero N} case N of zero then true else false end end