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

Type checker output contains type variable with suprising name in 3.13.0+dev11 #5553

Closed
vicuna opened this issue Mar 22, 2012 · 1 comment
Closed
Assignees

Comments

@vicuna
Copy link

vicuna commented Mar 22, 2012

Original bug ID: 5553
Reporter: rdicosmo
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2013-08-31T10:48:50Z)
Resolution: fixed
Priority: low
Severity: minor
Fixed in version: 4.00.0+dev
Category: typing

Bug description

In the following example code, the type of the lengthIn the following example code, the type of the length
function contains a type variable with a surprising name:

type ('a, 'b) l =
Nil : ('a, 'b) l
| Cons : 'b * ('a, 'b) l -> ('a, 'b) l;;

let rec length : type a b. (a,b) l -> 'a = function
| Nil -> 0
| (Cons (_,r)) -> 1+ (length r);;

Indeed, in 3.13.0+dev11 (2012-01-26), we get

val length : ('a1, 'b) l -> int =

The 'a1 in the type is quite puzzling, and it would
be better to print 'a in place of it
function contains a type variable with a surprising name:

type ('a, 'b) l =
Nil : ('a, 'b) l
| Cons : 'b * ('a, 'b) l -> ('a, 'b) l;;

let rec length : type a b. (a,b) l -> 'a = function
| Nil -> 0
| (Cons (_,r)) -> 1+ (length r);;

Indeed, in 3.13.0+dev11 (2012-01-26), we get

val length : ('a1, 'b) l -> int =

The 'a1 in the type is quite puzzling, and it would
be better to print 'a in place of it.

Steps to reproduce

Just type

type ('a, 'b) l =
Nil : ('a, 'b) l
| Cons : 'b * ('a, 'b) l -> ('a, 'b) l;;

let rec length : type a b. (a,b) l -> 'a = function
| Nil -> 0
| (Cons (_,r)) -> 1+ (length r);;

Additional information

If we use different names for the type variables in the GADT,
the problem does not show up

let rec length : type d e. (d,e) l -> 'a = function
| Nil -> 0
| (Cons (_,r)) -> 1+ (length r);;

val length : ('d, 'e) l -> int =

Here is what Jonathan hinted at as a potential explanation

Jacques Garrigue recently implemented a patch that tries to keep user-provided
type names when printing out types, and also when giving error
messages. In your
example, there probably is an internal variable that's called "a" because of the
type name you provided. Some wizardry happens with GADTs, so another type
variable is generated. The other one ends up being printed, and because it's
called "a" too, the type-checker has to find another suitable name.

Or something like that. Maybe change type a b. to type foo bar. will give
different results :).

@vicuna
Copy link
Author

vicuna commented Mar 23, 2012

Comment author: @garrigue

Fixed by not allowing a type variable to have the same name as a local type in the "type a b. " syntactic sugar.

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