Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested withtype not translated correctly? #548

Open
andreasabel opened this issue Feb 10, 2024 · 3 comments
Open

Nested withtype not translated correctly? #548

andreasabel opened this issue Feb 10, 2024 · 3 comments

Comments

@andreasabel
Copy link

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.

@pclayton
Copy link

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.

@andreasabel
Copy link
Author

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.

@MatthewFluet
Copy link
Member

Using an annotation to support the SML/NJ-style elaboration of withtype would be a reasonable approach. PR welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants