10.1 Recursive Types
TBoS p.250-253
Now consider a simple recursive type; the type natnum of all natural numbers in successor notation:
0
[succ 0]
[succ [succ 0]] ...
(1+) (datatype natnum
___________
0 : natnum;
N : natnum;
==================
[succ N] : natnum;)
type#natnum : symbol
(2+) 0
0 : number
(3+) 0 : natnum
0 : natnum
(4+) [succ 0]
[succ 0] : natnum |
A more complex type; the type of all fully parenthesised arithmetic expressions in list form.
(5+) (datatype arithexpr
N : number;
___________
N : arithexpr;
if (element? Op [+ / - *])
M : arithexpr; N : arithexpr;
=============================
[M Op N] : arithexpr;)
type#arithexpr : symbol
(6+) [9 + 7]
[9 + 7] : arithexpr
|
|