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

constraints dropped on included signature #6527

Closed
vicuna opened this issue Aug 29, 2014 · 2 comments
Closed

constraints dropped on included signature #6527

vicuna opened this issue Aug 29, 2014 · 2 comments
Assignees
Milestone

Comments

@vicuna
Copy link

vicuna commented Aug 29, 2014

Original bug ID: 6527
Reporter: mkoconnor
Assigned to: @lpw25
Status: closed (set by @xavierleroy on 2016-12-07T10:49:09Z)
Resolution: won't fix
Priority: normal
Severity: minor
Version: 4.01.0
Target version: 4.02.2+dev / +rc1
Category: typing
Monitored by: @gasche

Bug description

It seems constraints are dropped when including a signature in the following way:

$ ocaml
OCaml version 4.01.0

module type With_constraint = sig type 'a t constraint 'a = [> `Foo] end;;

module type With_constraint = sig type 'a t constraint 'a = [> `Foo ] end

module type S = sig type 'a t include With_constraint with type 'a t := 'a t end;;

module type S = sig type 'a t end

This surprised me, since the constraint doesn't get dropped if there's a constraint on the type already defined in S:

module type S' = sig type 'a t constraint 'a = [> `Bar] include With_constraint with type 'a t := 'a t end;;

Error: In this with' constraint, the new definition of t does not match its original definition in the constrained signature: Type declarations do not match: type 'a t = 'a t constraint 'a = [> Bar | Foo ] is not included in type 'a t constraint 'a = [> Foo ]
Their constraints differ.

@vicuna
Copy link
Author

vicuna commented May 5, 2015

Comment author: @lpw25

This behaviour is probably the correct approach for handling this situation, as I think it is the most flexible sound approach.

For a module type like:

module type S = sig type 'a t constraint 'a = [> `Foo] end

You can think of

S with type 'a t := 'a s

as meaning "S with all occurrences of [> Foo] t replaced by [> Foo] s".

This operation works if "[> Foo] s" is a valid type (e.g. your first example), and fails if "[> Foo] s" is not a valid type (e.g. your second example).

It may appear that [> Foo] s is valid in your second example, but really if you write [> Foo] s you actually get [> Foo | Bar] s instead -- it is not possible to have precisely [> `Foo] s.

@vicuna
Copy link
Author

vicuna commented May 5, 2015

Comment author: @lpw25

Also note that the only alternative is to have:

module type With_constraint = sig type 'a t constraint 'a = [> `Foo] end;;
module type S = sig type 'a t include With_constraint with type 'a t := 'a t end;;

result in an error.

It would not be safe to have the include of With_constraint retroactively change the definition of the type t to add constraints.

@vicuna vicuna closed this as completed Dec 7, 2016
@vicuna vicuna added this to the 4.02.2 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
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