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

type 'a x = [> ] as 'a and 'a t = { z : 'a x } doesn't compile #6320

Closed
vicuna opened this issue Feb 5, 2014 · 2 comments
Closed

type 'a x = [> ] as 'a and 'a t = { z : 'a x } doesn't compile #6320

vicuna opened this issue Feb 5, 2014 · 2 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Feb 5, 2014

Original bug ID: 6320
Reporter: pw374
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2015-12-11T18:25:40Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 4.01.0
Category: typing

Bug description

type 'a x = [> ] as 'a
type 'a t = { z : 'a x }

compiles just fine but

type 'a x = [> ] as 'a
and 'a t = { z : 'a x }

doesn't.

I'm not sure that it's a bug but if it's not, I really don't see why and I'd love some explanations.
Cheers.

Steps to reproduce

  1. Compile a file that only has
    type 'a x = [> ] as 'a
    type 'a t = { z : 'a x }

  2. Compile a file that only has
    type 'a x = [> ] as 'a
    and 'a t = { z : 'a x }

Additional information

The error message is:

Error: Constraints are not satisfied in this type.
Type 'a x should be an instance of [> ] x

@vicuna
Copy link
Author

vicuna commented Feb 6, 2014

Comment author: @garrigue

When a type abbreviation has a constraint, it is not propagated automatically to mutually recursive types.
This is to allow type abbreviations to be used polymorphically inside the recursion.

As a result you must propagate the constraint by hand:

type 'a x = [> ] as 'a
and 'a t = { z : ([> ] as 'a) x }

@vicuna
Copy link
Author

vicuna commented Feb 6, 2014

Comment author: pw374

Ok, thanks.

However it's quite inconvenient if instead of just [> ] we have a rather big sum [> Int of int | String of string | ...etc... ], since we'd have to repeat that big sum as many times at it's used by different types...

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

No branches or pull requests

2 participants