Skip to content
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

Allow contractibility annotation in abstract types interface #5863

Open
vicuna opened this issue Dec 25, 2012 · 7 comments
Open

Allow contractibility annotation in abstract types interface #5863

vicuna opened this issue Dec 25, 2012 · 7 comments

Comments

@vicuna
Copy link

vicuna commented Dec 25, 2012

Original bug ID: 5863
Reporter: @gasche
Status: acknowledged (set by @damiendoligez on 2013-06-28T16:12:38Z)
Resolution: open
Priority: normal
Severity: feature
Version: 4.00.0
Target version: later
Category: typing
Related to: #5343

Bug description

The fix to #5343 has the compiler safely assume that abstract types are possibly non-contractive. This has the downside of making the following example fail:

# #rectypes;;
# module Fixpoint (M : sig type 'a t end) = struct type fix = fix M.t end;;
# module Nat = Fixpoint(struct type 'a t = 'a option end);;

Since 4.00.0 this doesn't compile anymore, as "fix" is rejected because M.t is potentially non-contractive.

Could we have a way to specify in a signature that a type is contractive?

  type 'a t : contractive

(Another option would be to have a type comparison check that is robust in present of type cycles, as in http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.225.6241 , but that is probably not a realistic medium-term change.)

@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale label May 15, 2020
@garrigue
Copy link
Contributor

Still worth considering.
Note that nominal types are contractive, so adding them would already be an improvement.

garrigue added a commit to garrigue/ocaml that referenced this issue May 20, 2020
@github-actions github-actions bot removed the Stale label Jun 19, 2020
garrigue added a commit to garrigue/ocaml that referenced this issue Aug 7, 2020
@github-actions
Copy link

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.

@laelath
Copy link
Contributor

laelath commented Nov 7, 2023

I am trying to write a library that would benefit from this feature! Is there anything serious that would be blocking a merge of this feature if implemented?

@gasche
Copy link
Member

gasche commented Nov 7, 2023

A first step would be to agree on the syntax. My proposal type 'a t : contractive above is not necessarily a good choice, because:

  • it looks very different from existing variance-style annotation syntaxes, and
  • it does not clearly extend to multi-parameter types (for example type ('a, 'b) t = 'a is contractive in 'b but not in 'a).

It may be a matter of agreeing on a weird new symbol to add to variance-like markers +, -, ! to indicate contractiveness.

Then you have to implement it. I expect that this will be difficult, but easier than agreeing on the syntax :-)

@laelath
Copy link
Contributor

laelath commented Nov 9, 2023

From what I understand, adding the annotation to the type declaration in the module is the only place it's appropriate, so it probably doesn't belong with the variance annotations. Maybe something like type 'a t : contractive 'a? Seems like a good enough choice to prototype with

@gasche
Copy link
Member

gasche commented Nov 9, 2023

I'm not sure I follow. My idea is to add this on type declarations (and optionally on type definitions but there it can be inferred), in particular on type declarations in the argument of a functor, and to be able to annotate each parameter. For example the following should work, assuming I use # for contractibility:

module F(X: sig type (#'a, 'b) t end) = struct type u = (u, unit) X.t end

module M = struct type ('a, 'b) = 'b end
module N = F(M)

This seems similar to variance to me:

module F(X: sig type (+'a, -'b) t end) = struct type +'a u = ('a * 'a, 'a -> unit) X.t end

module M = struct type ('a, 'b) t = 'b -> 'a end
module N = F(M)

@Octachron Octachron removed the Stale label Nov 9, 2023
@Octachron Octachron reopened this Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants