0

I am writing an application where I want to define many types in the withtype clause of a datatype declaration. The following code snippet demonstrates it:

datatype ta = A
withtype tb = int
     and tc = tb

mlton fails to compile this code, although smlnj succeeds.

$ mlton -stop o test.sml
Error: test.sml 3.15.
  Undefined type tb.
compilation aborted: parseAndElaborate reported errors

I am using mlton-20100608 and smlnj-110.71.

Is this a bug in mlton?

I do not know how to proceed without this sort of declaration: a set of mutually recursive datatypes and types.

The idea comes from the abstract syntax tree types proposed by Andrew Appel for the Tiger language in his book Modern Compiler Implementation in ML, page 98, in file absyn.sml

4

1 回答 1

1

根据 mlton 社区的 Andreas Rossberg 的说法,这不是 mlton 的错误,而是与 SML/NJ 部分标准的(已知)偏差。根据规范,后面的类型缩写withtype不是相互递归的,只有前面的数据类型。该示例被重写为

datatype ta = A
type tb = int
and tc = tb

也就是说,MLton 正确地标记了这一点。

总是可以在右侧扩展其他类型的构造函数,因此没有真正的限制。但是,必须这样做可能会很麻烦。

于 2012-10-23T11:56:18.930 回答