You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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.
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.
The text was updated successfully, but these errors were encountered: