mlton
mlton copied to clipboard
Nested `withtype` not translated correctly?
SML/NJ understands this:
datatype Entry =
e_val of string*Clos
| e_gen of string*int
withtype Env = Entry list
and Clos = Tm*Env
MLton 20210117 (latest on homebrew) gives this error:
Undefined type: Env.
So, it seems that the types in withtype
do not know each other.
This behavior is in line with SML as specified by the Definition. Poly/ML, for example, would give you a similar response. You are not the first to observe this - see this response. Unfortunately compiler extensions lead to non-portable code.
It is of course possible to work around this limitation (by inlining either Clos
or Env
), but it is not super pretty.
But I understand that standards are not easily changed, even if they made suboptimal decisions...
Maybe an extension could be implemented, similar to the -default-ann 'allowSigWithtype true'
, e.g. allowRecursiveWithtype
.
Using an annotation to support the SML/NJ-style elaboration of withtype
would be a reasonable approach. PR welcome.