Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006256OCamlOCaml typingpublic2013-12-02 00:402013-12-02 03:17
Reportersebmondet 
Assigned Togarrigue 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionno change required 
PlatformOSOS Version
Product Version4.01.0 
Target VersionFixed in Version 
Summary0006256: Open Polymorphic Variants, difference between 4.00.1 and 4.01.0
Description
This code used to compile fine with 4.00.1:

module type T = sig
  type t
  val f : t -> ([> `A | `B ] -> t) -> t
end

module Tt : T = struct
  type t = [ `A | `B ]
  let f t g = g (t :> [> `A | `B])
end

but with 4.01.0, I get:

Error: Signature mismatch:
       Modules do not match:
         sig
           type t = [ `A | `B ]
           val f : ([> `A | `B ] as 'a) -> ('a -> 'b) -> 'b
         end
       is not included in
         T
       Values do not match:
         val f : ([> `A | `B ] as 'a) -> ('a -> 'b) -> 'b
       is not included in
         val f : t -> ([> `A | `B ] -> t) -> t


PS: Is there a more future proof work-around that does not imply expanding a match-with? like this:

module Tt : T = struct
  type t = [ `A | `B ]
  let f t g =
    match t with
    | `A -> g `A
    | `B -> g `B
end



TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0010685)
garrigue (manager)
2013-12-02 03:17

If you look at the type inferred in 4.00 (and previous version) you can see that this is a bug in the type subsumption check, which was fixed in 4.01:
# module Tt = struct
     type t = [ `A | `B ]
    let f t g = g (t :> [> `A | `B])
  end;;
module Tt :
  sig
    type t = [ `A | `B ]
    val f : ([> `A | `B ] as 'a) -> ('a -> 'b) -> 'b
  end

Clearly the type inferred for f does not contain "t -> [> `A | `B] -> t -> t", as it requires that t and the argument of g have the same type.

The right way to write f is:

  # let f (#t as t) g = g t;;
  val f : [< t ] -> ([> t ] -> 'a) -> 'a

- Issue History
Date Modified Username Field Change
2013-12-02 00:40 sebmondet New Issue
2013-12-02 03:17 garrigue Note Added: 0010685
2013-12-02 03:17 garrigue Status new => resolved
2013-12-02 03:17 garrigue Resolution open => no change required
2013-12-02 03:17 garrigue Assigned To => garrigue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker