我试图在无类型 Racket 中模仿 OCaml 中的递归类型,但我似乎找不到关于定义递归结构的文档。我将如何进行映射:
type example =
| Red
| Blue of example
| Yellow of example * example;;
进入球拍中的东西?
我尝试了以下方法:
(struct Red ())
(struct Blue (e1))
(struct Yellow (e1 e2))
(struct example/c
(or/c (Red)
(Blue example/c)
(Yellow example/c example/c)))
但是,当我将 example/c 放入合同时,它并没有按预期工作,因为它声称这是一个程序。有什么帮助吗?