- (* Again, to use this you'll want to call `fun next -> sysf_succ sysf_zero next` *)
-
- let sysf_pred (n : 'a sysf_nat) : 'a sysf_nat = (* NOT DONE *)
-
-<!--
- (* Using a System F-style encoding of pairs, rather than native OCaml pairs ... *)
- let pair a b = fun f -> f a b in
- let snd x y next = y next in
- let shift p next = p (fun x y -> pair (sysf_succ x) x) next in (* eta-expanded as in previous definitions *)
- fun next -> n shift (pair sysf_zero sysf_zero) snd next
-
- let pair = \a b. \f. f a b in
- let snd = \x y. y in
- let shift = \p. p (\x y. pair (succ x) x) in
- let pred = \n. n shift (pair 0 err) snd in
--->
-
+ (* Again, to get a polymorphic result you'll want to call `fun next -> sysf_succ sysf_zero next` *)
+
+ And here is how to get `sysf_pred`, using a System-F-style encoding of pairs. (For brevity, I'll leave off the `sysf_` prefixes.)
+
+ type 'a natpair = ('a nat -> 'a nat -> 'a nat) -> 'a nat
+ let natpair (x : 'a nat) (y : 'a nat) : 'a natpair = fun f -> f x y
+ let fst x y = x
+ let snd x y = y
+ let shift (p : 'a natpair) : 'a natpair = natpair (succ (p fst)) (p fst)
+ let pred (n : ('a natpair) nat) : 'a nat = n shift (natpair zero zero) snd
+
+ (* As before, to get polymorphic results you need to eta-expand your applications. Witness:
+ # let one = succ zero;;
+ val one : '_a nat = <fun>
+ # let one next = succ zero next;;
+ val one : ('a -> 'a) -> 'a -> 'a = <fun>
+ # let two = succ one;;
+ val two : '_a nat = <fun>
+ # let two next = succ one next;;
+ val two : ('a -> 'a) -> 'a -> 'a = <fun>
+ # pred two;;
+ - : '_a nat = <fun>
+ # fun next -> pred two next;;
+ - : ('a -> 'a) -> 'a -> 'a = <fun>
+ *)