Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006527OCamlOCaml typingpublic2014-08-30 00:522015-05-05 18:40
Reportermkoconnor 
Assigned Tolpw25 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionwon't fix 
PlatformOSOS Version
Product Version4.01.0 
Target Version4.02.2+dev / +rc1Fixed in Version 
Summary0006527: constraints dropped on included signature
DescriptionIt 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.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0013813)
lpw25 (developer)
2015-05-05 18:21

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.
(0013814)
lpw25 (developer)
2015-05-05 18:23

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.

- Issue History
Date Modified Username Field Change
2014-08-30 00:52 mkoconnor New Issue
2014-09-15 15:22 doligez Status new => acknowledged
2014-09-15 15:22 doligez Target Version => 4.02.2+dev / +rc1
2015-05-05 18:21 lpw25 Note Added: 0013813
2015-05-05 18:23 lpw25 Note Added: 0013814
2015-05-05 18:40 lpw25 Status acknowledged => resolved
2015-05-05 18:40 lpw25 Resolution open => won't fix
2015-05-05 18:40 lpw25 Assigned To => lpw25


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker