Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005924OCamltypingpublic2013-02-17 16:482015-12-11 19:18
Assigned Togarrigue 
StatusclosedResolutionwon't fix 
PlatformOSOS Version
Product Version4.00.1 
Target VersionFixed in Version 
Summary0005924: Adding expressiveness to polymorphic variants

I'd like to be able to do the kind of functions described here: [^]

This function:
  let f = function `A -> `C | `B -> `D | x -> x
is typed as:
  val f : ([> `A | `B | `C | `D ] as 'a) -> 'a
but a more fine type would be:
  val f : [ `A | `B | 'r ] -> [ `C | `D | 'r ]

gasche already told me that it is choice made by the caml developers, but I'm very interested in making such functions. So, if someone can add this expressiveness to the language or explain me why it is really not possible to add this, it would be very helpful.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
garrigue (manager)
2013-02-18 01:22

This is not strictly impossible to do that, but this requires huge changes in the type system.

* since we would have explicit row variables, you need to introduce a notion of type variable sort

* one would need to add exclusion information on row variables. For instance, with your example,
   we would the information that 'r cannot contain any of `A, `B, `C, `D. This is implicit in the type
   of f, but it can become hidden in more complex functions, so it would have to be explicit.

* typing of pattern-matching would have to compute remaining cases, which is not trivial in the general case.

For all these reasons there is no plan to introduce something like that at this point.

If you are interested in this subject, you can read papers by Didier Rémy and, more recently, Matthias Blume.

- Issue History
Date Modified Username Field Change
2013-02-17 16:48 jpdeplaix New Issue
2013-02-18 01:22 garrigue Note Added: 0008854
2013-02-18 01:22 garrigue Status new => resolved
2013-02-18 01:22 garrigue Resolution open => won't fix
2013-02-18 01:22 garrigue Assigned To => garrigue
2015-12-11 19:18 xleroy Status resolved => closed
2017-02-23 16:45 doligez Category OCaml typing => typing

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker