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

Confusing error message at object type definition #5224

Closed
vicuna opened this issue Feb 14, 2011 · 2 comments
Closed

Confusing error message at object type definition #5224

vicuna opened this issue Feb 14, 2011 · 2 comments
Assignees
Labels

Comments

@vicuna
Copy link

vicuna commented Feb 14, 2011

Original bug ID: 5224
Reporter: furuse
Assigned to: @garrigue
Status: closed (set by @garrigue on 2012-06-01T05:13:21Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.11.2
Fixed in version: 4.00.0+dev
Category: ~DO NOT USE (was: OCaml general)

Bug description

type 'x t = < f : 'y. 'y t >

gives me an error. I do not understand why this is rejected, but the reason is not the issue. The problem is the error message:

Error: In the definition of t, type 'a t should be 'b t

This should be printed as type 'y t should be 'x t .

@vicuna
Copy link
Author

vicuna commented May 31, 2012

Comment author: @protz

This is rejected because this type is non-regular, i.e. it is a parameterized structural type where which is instanciated with a different type parameter.

This is also the reason why the code snippet below is rejected:

type 'a foo = [A | B of ('a foo) foo];;

Error: In the definition of foo, type 'a foo foo should be 'a foo

The solution is to define an intermediary nominal type:

type 'a tmp = T of 'a t

Then:

type 'x t = < f : 'y. 'y tmp >

Of course you need these two types to be mutually recursive.

type 'a tmp = Tmp of 'a t and 'a t = < f: 'y. 'y tmp >;;

type 'a tmp = Tmp of 'a t
and 'a t = < f : 'y. 'y tmp >

@vicuna
Copy link
Author

vicuna commented Jun 1, 2012

Comment author: @garrigue

Fixed in trunk and 4.00, revisions 12533 and 12534.

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

No branches or pull requests

2 participants