New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Abstract type and private type don't have same behavioir with type equality #7739
Comments
Comment author: @garrigue Interesting. In the case of an abstract type, we add an equation and are done. |
Comment author: @gasche From the soundness point of view I think there is no problem: it is always sound to forget a type definition, so from |
Comment author: kantian I tend to be agree with gasche, and we can encode his argumentation with functor.
|
Comment author: @garrigue My problem is not soundness, but principality: |
Comment author: kantian I'm not sure I understand your questions, since principality problematic is not clear to me. By the way, currently one can rely on elemantary theory of equality to perform the desired cast. This works in all situations (abstract type, private abbreviations for both types...)
I have just a question: what did you mean by this in your first reply?
|
Comment author: @garrigue Then here is an example of the problem type (_,_) eq = Refl : ('a, 'a) eq
module M : sig type t = private int val eq : (t, int) eq end =
struct type t = int let eq = Refl end
module N : sig type t = private M.t val eq : (t, int) eq end =
struct type t = M.t let eq = M.eq end
module P : sig type t = private N.t val eq : (t, M.t) eq end =
struct type t = N.t let eq = N.eq end
let f1 (i : P.t) = match P.eq with Refl -> (i :> int);;
let f2 (i : P.t) = match P.eq with Refl -> (i :> N.t);; There are two option for the match here: either replace M.t = P.t = private N.t and N.t = private M.t ... But this doesn't mean that the first option is the correct one: f2 already types currently |
Comment author: kantian Ok, I think that I better understand the problem. Your second case is interresting, it can currently be encoded in OCaml an it leads the type checker in an infinite loop. ;-) Here is the first option:
Here your second option:
There is even a more agressive solution : forget both private abbreviations, but in this case none of your functions type check. Now, I'm not really sure there is a safe solution regarding subtyping and principality problematic. Currently, the most safe way could be to rely on general principles of type equality as I did in my previous reply. |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
Extra comment: I was too fast in dismissing soundness as a problem here. I'm currently working on adding equations for nominal types (#9042), but I think I will have to stick to abstract types, or be very restrictive on the compatibility of the two definitions. |
By the way, I don't think this is a bug. An incompleteness, yes, but the specification only says that we add equations to abstract types. |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
Original bug ID: 7739
Reporter: kantian
Assigned to: @garrigue
Status: confirmed (set by @garrigue on 2018-02-26T06:26:13Z)
Resolution: open
Priority: normal
Severity: minor
Category: typing
Related to: #7747
Monitored by: @gasche @lpw25
Bug description
After a discussion on OCaml discuss, I noticed there is a different behavior between abstract types and private aliased types against type equality. Leo White advised me to report this on Mantis, hence I do.
Steps to reproduce
The text was updated successfully, but these errors were encountered: