在OCAML中,这种相互递归类型的定义的用途是什么?

问题描述 投票:0回答:1
贝洛是OCAML中的有效类型定义。

type t = U of u and u = T of t

有使用吗?
如何创建类型

t

的值?或键入

u

	

您所展示的示例没有多大意义。递归无法结束。但是这样,相互递归类型可以是 非常有用。考虑从标准库中的
ocaml
1个回答
0
投票
定义。

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. *)

Source
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.