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

Odd behaviour of type expressions in polymorphic variant tag specifications #6124

Closed
vicuna opened this issue Aug 6, 2013 · 3 comments
Closed
Assignees

Comments

@vicuna
Copy link

vicuna commented Aug 6, 2013

Original bug ID: 6124
Reporter: @lpw25
Assigned to: @garrigue
Status: resolved (set by @garrigue on 2017-03-14T10:07:41Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.01.0+dev
Target version: undecided
Fixed in version: 4.06.0 +dev/beta1/beta2/rc1
Category: typing
Monitored by: @lpw25

Bug description

I'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 =

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

@vicuna
Copy link
Author

vicuna commented Jan 17, 2015

Comment author: @garrigue

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.

@vicuna
Copy link
Author

vicuna commented Jan 17, 2015

Comment author: @lpw25

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.

@vicuna
Copy link
Author

vicuna commented Mar 14, 2017

Comment author: @garrigue

Error message changed by commit d0abe2c.

New error message is: The type ... does not expand to a polymorphic variant type.

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

2 participants