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

The type variables given in a type definition are not used for inference #5446

Closed
vicuna opened this issue Dec 23, 2011 · 3 comments
Closed
Assignees

Comments

@vicuna
Copy link

vicuna commented Dec 23, 2011

Original bug ID: 5446
Reporter: pilki
Assigned to: @garrigue
Status: closed (set by @garrigue on 2011-12-24T03:21:15Z)
Resolution: not a bug
Severity: feature
Category: ~DO NOT USE (was: OCaml general)
Child of: #5444
Monitored by: @protz

Bug description

Say you give fancy names for type variables in a type definition:
<<<
type ('fst, 'snd) mypair = MkMyPair of 'fst * 'snd

those type variables are not used for inference. For example:
<<<
let mk x y = MkMyPair (x, y)

The infered type is
val mk : 'a -> 'b -> ('a, 'b) mypair
and one might expect to have
val mk: 'fst -> 'snd -> ('fst, 'snd) mypair

Additional information

I don't know what would be a nice "specification" for such a feature. What for example should be the type of

let swap (MkMyPair (x, y)) = MkMyPair (y, x)

val swap : ('fst, 'snd) mypair -> ('snd, 'fst) mypair
or
val swap : ('snd, 'fst) mypair -> ('fst, 'snd) mypair

What when you have several instance of the same type constructor with different type variables ? Add a 0, 1.. ? then every function on lists would have types of the form
val map: ('a -> 'a0) -> 'a list -> 'a0 list

I do not know if this is solvable.

@vicuna
Copy link
Author

vicuna commented Dec 23, 2011

Comment author: pilki

To open the syntax troll :)

Maybe we could have something like

type '_a list = Nil | Cons of ('_a * '_a list)

to say "I don't want the type variable name to be used later on"

and
type ('fst, 'snd) mypair = MkPair of ('fst, 'snd)

to say "please use my type variable names!"

@vicuna
Copy link
Author

vicuna commented Dec 24, 2011

Comment author: @garrigue

Same comment as #5447.
I'm not sure inheriting variable names from type definitions makes sense.

.@pilki Considering backward compatibility, it would be more reasonable to have no inheritance by default.
But introduce new syntax for explicit inheritance seems an overkill.
Using something like "only inherit names of 2 characters or more" might be an option.

@vicuna
Copy link
Author

vicuna commented Dec 24, 2011

Comment author: @garrigue

Might consider some future action, but this is not a bug.

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