You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: