【发布时间】:2015-06-10 21:16:00
【问题描述】:
在 Haskell 中,您可以执行以下操作:
Prelude> data Foo = Foo Bar; data Bar = Bar Foo
如何在 OCaml 中做同样的事情?我试过了:
___
# type foo = Foo of bar;; type bar = Bar of foo;;
Error: Unbound type constructor bar
是否可以在 OCaml 中定义相互递归的数据类型?如果不是那为什么?
比较数据定义以让表达式:相互递归的数据类型对应于使用let rec(或者更合适的是type rec,因为需要更好的短语)。能够定义相互递归的数据类型有什么好处?我的 foobar 示例是微不足道的。您能想到相互递归数据类型的任何重要用途吗?
【问题讨论】:
标签: haskell recursion ocaml algebraic-data-types mutual-recursion