Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005663OCamlOCaml typingpublic2012-06-26 16:282016-08-01 19:18
Assigned Togarrigue 
PlatformOSOS Version
Product Version 
Target Version4.02.3+devFixed in Version4.03.0+dev / +beta1 
Summary0005663: program (mistakenly?) rejected due to nongeneralizable type variable that appears nowhere
DescriptionThe program below is rejected by the type checker.

  module F (M : sig
     type 'a v = string
     include sig
        type 'a t
        type 'a u
        val f : unit -> _ t
        val g : 'a t -> 'a u -> unit
     end with type 'a u := 'a v
  end) = struct
     open M

     let t = (f () (*: unit v t*)) (* uncomment here to make it type check *)
     let () = g t "foo"

The error message is:

  Error: The type of this module,
           (M : sig
                  type 'a v = string
                  type 'a t
                  val f : unit -> 'a t
                  val g : 'a t -> 'a v -> unit
                end) ->
           sig val t : '_a M.t end,
         contains type variables that cannot be generalized

I think this program should be accepted. The type variable that OCaml
is complaining about is unused, if one expands out the types.
TagsNo tags attached.
Attached Filesdiff file icon closed_schema.diff [^] (6,009 bytes) 2015-04-21 09:08 [Show Content]

- Relationships

-  Notes
garrigue (manager)
2012-06-26 16:59

I'm not sure I understand your point here.
It seems that M.t is abstract in this program, so you cannot expand it.
So the type variable is really there, even if you didn't name it.
Writing "type +'a t" would probably solve the problem, if this is acceptable.
sweeks (reporter)
2012-07-24 20:47

Sorry, my example had a mistake. Here is a much simpler example:

  module F (M : sig
    type 'a t
    type 'a u = string
    val f : unit -> _ u t
  end) = struct
    let t = M.f ()

This causes the following error message:

  Error: The type of this module,
         (M : sig type 'a t type 'a u = string val f : unit -> 'a u t end) ->
         sig val t : '_a M.u M.t end,
       contains type variables that cannot be generalized

The type variable that OCaml is complaining about, ['_a], is in the
expression ['_a M.u], which OCaml knows is equivalent to [string]. I
don't see why OCaml should be complaining about ['_a], since it need
not appear in the type of [t], which has type [string M.t].

Adding a type constraint to [t] of the form [string M.t] isn't
sufficient to make the error go away. However, adding a type
constraint [unit M.u M.t] does make the error go away.
yallop (developer)
2014-08-18 23:41

With -short-paths the type variable doesn't even appear in the error message:

$ ocamlc -short-paths
File "", line 1, characters 9-109:
Error: The type of this module,
         (M : sig type 'a t type 'a u = bytes val f : unit -> bytes t end) ->
         sig val t : bytes M.t end,
       contains type variables that cannot be generalized
garrigue (manager)
2015-04-21 09:10

Added a patch which expands constructors while checking for non-generalizable variables.
This is disabled during class definitions, as it broke typing-poly/
garrigue (manager)
2015-04-22 09:17

Fixed in trunk, at revision 16030, by expanding type abbreviations while checking for nongeneralizable type variables.
Note that we only do it for compilation units.
For classes, this is not done, because typing-poly/ would fail.
lpw25 (developer)
2016-08-01 19:18

This change seems to cause 0007305

- Issue History
Date Modified Username Field Change
2012-06-26 16:28 sweeks New Issue
2012-06-26 16:59 garrigue Note Added: 0007610
2012-06-26 16:59 garrigue Assigned To => garrigue
2012-06-26 16:59 garrigue Status new => feedback
2012-07-06 15:21 doligez Target Version => 4.01.0+dev
2012-07-24 20:47 sweeks Note Added: 0007806
2012-07-24 20:47 sweeks Status feedback => assigned
2012-07-31 13:36 doligez Target Version 4.01.0+dev => 4.00.1+dev
2012-09-21 14:36 doligez Target Version 4.00.1+dev => 4.01.0+dev
2013-08-19 14:50 doligez Target Version 4.01.0+dev => 4.01.1+dev
2014-05-25 20:20 doligez Target Version 4.01.1+dev => 4.02.0+dev
2014-08-18 20:47 doligez Target Version 4.02.0+dev => 4.02.1+dev
2014-08-18 23:41 yallop Note Added: 0012019
2014-09-04 00:25 doligez Target Version 4.02.1+dev => undecided
2014-09-26 22:36 doligez Target Version undecided => 4.02.2+dev / +rc1
2015-02-26 19:15 doligez Target Version 4.02.2+dev / +rc1 => 4.02.3+dev
2015-04-21 09:08 garrigue File Added: closed_schema.diff
2015-04-21 09:10 garrigue Note Added: 0013692
2015-04-22 09:17 garrigue Note Added: 0013703
2015-04-22 09:17 garrigue Status assigned => resolved
2015-04-22 09:17 garrigue Fixed in Version => 4.03.0+dev / +beta1
2015-04-22 09:17 garrigue Resolution open => fixed
2016-08-01 19:18 lpw25 Note Added: 0016164

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker