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: 6467 Reporter:@mshinwell Assigned to:@garrigue Status: resolved (set by @garrigue on 2017-03-14T07:45:08Z) Resolution: duplicate Priority: normal Severity: minor Version: 4.01.0 Target version: undecided Category: typing Tags: recmod Related to:#5058#6011 Monitored by:@gasche
Bug description
The following code compiles.
module rec Element : sig
type t
val remove_from_container : t -> unit
end = struct
type t = {
level : Container.t;
}
let remove_from_container t =
Container.remove_element t.level t
end and Container : sig
type t
val remove_element : t -> Element.t -> unit
end = struct
type t = {
mutable elements : Element.t list;
}
let remove_element t element =
t.elements <-
List.filter (fun element' -> not (element == element')) t.elements
end
I would like to wrap the first definition of type [t] inside a module [T], like this:
module rec Element : sig
type t
val remove_from_container : t -> unit
end = struct
module T = struct
type t = {
level : Container.t;
}
end
include T
let remove_from_container t =
Container.remove_element t.level t
end and Container : sig
type t
val remove_element : t -> Element.t -> unit
end = struct
type t = {
mutable elements : Element.t list;
}
let remove_element t element =
t.elements <-
List.filter (fun element' -> not (element == element')) t.elements
end
This causes an error on the call to "Container.remove_element":
File "recmodules.ml", line 13, characters 37-38:
Error: This expression has type t = T.t
but an expression was expected of type Element.t
Is it expected that this causes an error? It seems surprising.
The text was updated successfully, but these errors were encountered:
This looks like an instance of the so-called double view problem: the same type seen from inside and outside a module ends up being not equal.
OCaml tries to solve it by adding an equation which makes local types point to their external definition.
However, this does not work if the type already has an equation, which is the case if it is a result of using "include".
In this respect, this is just a duplicate of some existing PR, if someone can find it...
I use the "site:caml.inria.fr/mantis" feature of Google to efficiently search the Mantis.
The double vision problem has been mentioned a couple of times, but not in this setting; there are other situations (unrelated to recursive modules) where the restriction of having a single equation was discussed, notably: #6011: #6011 #5058: #5058
As a practical matter, this is difficult only because of the abstract types. You can sidestep the issue by first defining the modules transparently, and sealing in a separate step:
Original bug ID: 6467
Reporter: @mshinwell
Assigned to: @garrigue
Status: resolved (set by @garrigue on 2017-03-14T07:45:08Z)
Resolution: duplicate
Priority: normal
Severity: minor
Version: 4.01.0
Target version: undecided
Category: typing
Tags: recmod
Related to: #5058 #6011
Monitored by: @gasche
Bug description
The following code compiles.
module rec Element : sig
type t
val remove_from_container : t -> unit
end = struct
type t = {
level : Container.t;
}
let remove_from_container t =
Container.remove_element t.level t
end and Container : sig
type t
val remove_element : t -> Element.t -> unit
end = struct
type t = {
mutable elements : Element.t list;
}
let remove_element t element =
t.elements <-
List.filter (fun element' -> not (element == element')) t.elements
end
I would like to wrap the first definition of type [t] inside a module [T], like this:
module rec Element : sig
type t
val remove_from_container : t -> unit
end = struct
module T = struct
type t = {
level : Container.t;
}
end
include T
let remove_from_container t =
Container.remove_element t.level t
end and Container : sig
type t
val remove_element : t -> Element.t -> unit
end = struct
type t = {
mutable elements : Element.t list;
}
let remove_element t element =
t.elements <-
List.filter (fun element' -> not (element == element')) t.elements
end
This causes an error on the call to "Container.remove_element":
File "recmodules.ml", line 13, characters 37-38:
Error: This expression has type t = T.t
but an expression was expected of type Element.t
Is it expected that this causes an error? It seems surprising.
The text was updated successfully, but these errors were encountered: