Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005663OCamlOCaml typingpublic2012-06-26 16:282014-09-26 22:36
Reportersweeks 
Assigned Togarrigue 
PrioritynormalSeverityminorReproducibilityalways
StatusassignedResolutionopen 
PlatformOSOS Version
Product Version 
Target Version4.02.2+devFixed in Version 
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"
  end

The error message is:

  Error: The type of this module,
         functor
           (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 Files

- Relationships

-  Notes
(0007610)
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.
(0007806)
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 ()
  end

This causes the following error message:

  Error: The type of this module,
       functor
         (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.
(0012019)
yallop (developer)
2014-08-18 23:41

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

$ ocamlc -short-paths pr5663.ml
File "pr5663.ml", line 1, characters 9-109:
Error: The type of this module,
       functor
         (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

- 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


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker