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

Strange typing restriction with polymorphic record fields #4382

Closed
vicuna opened this issue Sep 5, 2007 · 1 comment
Closed

Strange typing restriction with polymorphic record fields #4382

vicuna opened this issue Sep 5, 2007 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Sep 5, 2007

Original bug ID: 4382
Reporter: @mmottl
Status: closed (set by @garrigue on 2007-09-06T02:21:53Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.10+dev
Fixed in version: 3.10+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @mmottl

Bug description

In the following example I match + bind a record with a polymorphic field. The bound function is fully polymorphic and works without problems:


type t = { id : 'a. 'a -> 'a }

let mk_id () = { id = fun x -> x }

let { id = id } = mk_id ()

let () =
let x = id 0 in
let y = id 0. in
Printf.printf "%d %f\n" x y

But if I replace the line with the pattern match on the record field by the following:

let { id = id } as t = mk_id ()

then I get a type error:

File "foo.ml", line 9, characters 13-15:
This expression has type float but is here used with type int

It seems strange that adding the "as t" binding, which is not even used, would suddenly make "id" not fully polymorphic anymore, especially since the following, which should be semantically equivalent, works again:

let t = mk_id ()
let { id = id } = t

It is worth pointing out that OCaml 3.09.3 doesn't compile any but the most recent example.

It would be great if type inference in the above cases could be made more predictable and/or general.

@vicuna
Copy link
Author

vicuna commented Sep 6, 2007

Comment author: @garrigue

Fixed by avoid polymorphic fields in Typecore.build_as_type.

@vicuna vicuna closed this as completed Sep 6, 2007
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant