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

More relaxed scoping of type variables and polymorphic type annotations #6569

Closed
vicuna opened this issue Sep 18, 2014 · 2 comments
Closed

Comments

@vicuna
Copy link

vicuna commented Sep 18, 2014

Original bug ID: 6569
Reporter: @lpw25
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2016-12-07T10:36:58Z)
Resolution: not a bug
Priority: normal
Severity: feature
Version: 4.02.0
Category: typing
Related to: #6673
Monitored by: @hcarty

Bug description

The following definition fails:

# let foo : 'a. 'a list -> unit =
    fun (x : 'a list) -> ();;
  Characters 36-59:
      fun (x : 'a list) -> ();;
      ^^^^^^^^^^^^^^^^^^^^^^^
Error: This definition has type 'a list -> unit which is less general than
         'a0. 'a0 list -> unit

This is because the 'a in (x : 'a list) is scoped at the level of the let expression, whilst the : 'a . 'a list -> unit is considered to be just inside the let expression.

This means that 'a cannot be generalized, so the definition is less general than the type constraint.

It would be nice to relax this slightly to allow what is a perfectly reasonable coding style.

@vicuna
Copy link
Author

vicuna commented Sep 19, 2014

Comment author: @garrigue

There is a special syntax for such cases:

let foo : type a. a list -> unit =
fun (x : a list) -> ();;

The scoping works correctly here because a is locally abstract type
rather than a type variable. There are also other advantages.
(There is a drawback though, since currently we cannot use
locally abstract types for row variables. This is under consideration.)

@vicuna
Copy link
Author

vicuna commented Sep 19, 2014

Comment author: @lpw25

I don't think this request should be marked as resolved. Whilst you can use a different syntax to accomplish this, the feature request is to be able to use the (more visually appealing) 'a. ... syntax.

Also, as you note, we cannot use locally abstract types with rows. Even when we are able to I suspect that it will be a bit verbose, so it would be good to be able to use 'a. ... instead.

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