A more general form for recursive types in Nuprl is
ifA B thenF(A) F(B) , whereDef S T == x:S. x T
For example, we could have defined a non-primitive list type as
For the normal user, it should suffice that obviously monotonic functions on types will normally meet the criteria for forming a recursive type. (One exception is that
A type
Example: S-expressions
Here is a type definition inspired by lisp's S-expressions, which are binary trees with "atoms" at the leaves.
Def Sexpr(A) == rec(T.(TT)+A) Def Cons(s1;s2) == inl(<s1,s2>) Def Inj(a) == inr(a) Def Case of s : Inj(x) g(x) ; Cons(s1;s2) f(s1;s2)
Def == InjCase(s; s1s2. s1s2/s1,s2. f(s1;s2); x. g(x))
Thm* A:Type. Sexpr(A) Type Thm* A:Type. Sexpr(A) =ext (Sexpr(A)Sexpr(A))+A Thm* A:Type, s1,s2:Sexpr(A). Cons(s1;s2) Sexpr(A) Thm* A:Type, a:A. Inj(a) Sexpr(A)
Here is a recursive function that counts the number of leaves:
Def Size(s) == Case of s : Inj(x) 1 ; Cons(s1;s2) Size(s1)+Size(s2)
Def (recursive)Thm* A:Type, s:Sexpr(A). Size(s)
Thm* Size(Cons(Inj(1);Cons(Inj(2);Inj(1)))) = 3
Here is a recursive function that reverses an s-expression:
Def Reverse(e)
Def == Case of e
Def == CaInj(x) Inj(x)
Def == CaCons(s1;s2) Cons(Reverse(s2);Reverse(s1))
Def (recursive)Thm* A:Type, e:Sexpr(A). Reverse(e) Sexpr(A)
Thm* a,b,c:X.
Thm* Reverse(Cons(Inj(a);Cons(Inj(b);Inj(c))))
Thm* =
Thm* Cons(Cons(Inj(c);Inj(b));Inj(a))
Functions over recursive types are usually themselves recursive. See
About: