type t = U of u and u = T of t
有使用吗?如何创建类型
t
u
?
您所展示的示例没有多大意义。递归无法结束。但是这样,相互递归类型可以是 非常有用。考虑从标准库中的
type 'a t = unit -> 'a node
(** A sequence [xs] of type ['a t] is a delayed list of elements of
type ['a]. Such a sequence is queried by performing a function
application [xs()]. This function application returns a node,
allowing the caller to determine whether the sequence is empty
or nonempty, and in the latter case, to obtain its head and tail. *)
and +'a node =
| Nil
| Cons of 'a * 'a t (**)
(** A node is either [Nil], which means that the sequence is empty,
or [Cons (x, xs)], which means that [x] is the first element
of the sequence and that [xs] is the remainder of the sequence. *)