1

I'm following this paper: Introduction to Functional Programming. In the chapter on the ML language family there are examples to be run with camllight. However, in Debian repositories, I haven't found any package that contains camllight, so I'm using ocaml instead:

$ ocaml
    OCaml version 4.01.0

Example code from the paper worked fine until this one from the part on custom type definitions:

#type ('a,'b)sum = inl of 'a | inr of 'b;;

Trying this one out with ocaml outputs:

# type ('a,'b)sum = inl of 'a | inr of 'b;;
Error: Syntax error

with the first of underlined.

Why the syntax error? Is this some language feature of camllight that is not present in ocaml? Or can I enable it somehow?

4

1 回答 1

4

这有效:

# type ('a,'b)sum = Inl of 'a | Inr of 'b;;

在 OCaml 中,您需要将构造函数的第一个字母大写。

编辑1:我还注意到在你链接的论文中,他后者的构造函数的第一个字母大写。我还在 caml light 文档中注意到他们也使用相同的符号。所以也许这是论文中的错误?

Edit2:我最终安装了 caml light,看来在 caml light 中首字母大写并不重要。与 OCaml 不同,任何一种方式都可以。

于 2015-03-28T00:15:35.277 回答