1

Background: I'm using Emacs 23.3, OCaml 3.12.0 and tuareg 1.45.7.

I'm looking at the Hickey OCaml book, and trying to run the examples on pg. 157 of the book, 167 of the .pdf. The problem arises with the expression

type ’a blob = < draw : unit; .. > as ’a

When I type that into my emacs buffer in tuareg-mode, and try to evaluate it with C-c C-e, I get the following error in the caml toplevel:

# type 'a blob = < draw : unit; .. > as ';;
Characters 39-41:
  type 'a blob = < draw : unit; .. > as ';;
                                         ^^
Error: Syntax error

Notice how the final a doesn't appear in command sent to the toplevel. If I type the line into the toplevel directly, it works just fine:

# type 'a blob = < draw : unit; .. > as 'a;;
type 'a blob = 'a constraint 'a = < draw : unit; .. >

So my question is: Why doesn't this work, and how can I fix it? Updating tuareg doesn't seem to be an option: I've tried to use tuareg version 2.0, but that won't even load properly.

Update: This was fixed in the tuareg SVN trunk as of 12/8/12. I don't think they've updated the release with the fix, but you can grab the trunk anonymously with

svn checkout svn://svn.forge.ocamlcore.org/svn/tuareg/trunk

bearing in mind the usual caveats about development vs. release versions.

4

1 回答 1

3

这是图阿雷格的一个错误。由于某种原因,他无法正确计算短语的结尾。要解决它,有两种可能性:

  • 将您的类型括在括号中:type 'a t = (<..> as 'a)有效

  • 手动将其发送到顶层:复制该行,将其粘贴到顶层缓冲区中,然后添加;;(顶层中的短语分隔符,在可以推断时在源代码中可选)。

编辑:似乎该错误已在上游报告。希望他们迟早会修复它。

于 2011-04-24T06:06:16.280 回答