Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006124OCamlOCaml typingpublic2013-08-06 18:042015-01-17 08:44
Reporterlpw25 
Assigned Togarrigue 
PrioritynormalSeverityminorReproducibilityN/A
StatusassignedResolutionopen 
PlatformOSOS Version
Product Version4.01.0+dev 
Target Version4.03.0+devFixed in Version 
Summary0006124: Odd behaviour of type expressions in polymorphic variant tag specifications
DescriptionI'm sure Jacques is already aware of this behaviour, but I find the following behaviour a bit odd, and at the very least the error message could be improved:

  # let f : ([`A | `B ] as 'a) -> [> 'a ] -> unit = fun x y -> ();;
  val f : [ `A | `B ] -> [> `A | `B ] -> unit = <fun>

  # let f : ([`A | `B ] as 'a) -> [> 'a] -> unit = fun x (y : [> 'a]) -> ();;
  Characters 61-63:
    let f : ([`A | `B ] as 'a) -> [> 'a] -> unit = fun x (y : [> 'a]) -> ();;
                                                                 ^^
  Error: The type 'a is not a polymorphic variant type

  # let f (x : [`A | `B] as 'a) (y : [> 'a]) = ();;
  Characters 36-38:
    let f (x : [`A | `B] as 'a) (y : [> 'a]) = ();;
                                      ^^
  Error: The type 'a is not a polymorphic variant type
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0013128)
garrigue (manager)
2015-01-17 01:55

For principality reasons, bindings of type variables are not propagated to pattern-matchings containing polymorphic variants.
Improving the error message is possible, but this seems lots of code to little effect: one has to check whether the type is a variable, and whether its actual binding is a polymorphic variant or not, to finally decide outputting a very specialized error message...
Another approach is to restrict syntactically: polymorphic variant inheritance is only intended to be used with defined types.
(0013133)
lpw25 (developer)
2015-01-17 08:44

> Another approach is to restrict syntactically: polymorphic variant inheritance is only intended to be used with defined types.

I think that this would be a good idea, because it probably works for all the actual code out there and is less confusing for people.

> Improving the error message is possible, but this seems lots of code to little effect: one has to check whether the type is a variable, and whether its actual binding is a polymorphic variant or not, to finally decide outputting a very specialized error message...

I actually just meant changing the wording because the statement "'a is not a polymorphic variant type" is not really true, so a wording that is more clear that 'a is not known to be a polymorphic variant type when defining [> 'a] would be less confusing. Basically the current error sounds a bit too much like a unification error, whilst 'a can clearly be unified with a polymorphic variant.

- Issue History
Date Modified Username Field Change
2013-08-06 18:04 lpw25 New Issue
2013-08-06 18:45 gasche Note Added: 0010134
2013-08-06 19:31 gasche Note Deleted: 0010134
2013-08-19 19:10 doligez Status new => acknowledged
2013-08-19 19:10 doligez Target Version => 4.01.1+dev
2014-05-25 20:20 doligez Target Version 4.01.1+dev => 4.02.0+dev
2014-07-24 22:48 doligez Target Version 4.02.0+dev => 4.02.1+dev
2014-09-04 00:25 doligez Target Version 4.02.1+dev => undecided
2014-09-24 00:02 doligez Target Version undecided => 4.02.2+dev / +rc1
2015-01-16 23:47 doligez Assigned To => garrigue
2015-01-16 23:47 doligez Status acknowledged => assigned
2015-01-16 23:47 doligez Target Version 4.02.2+dev / +rc1 => 4.03.0+dev
2015-01-17 01:55 garrigue Note Added: 0013128
2015-01-17 08:44 lpw25 Note Added: 0013133


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker