Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004382OCamlOCaml generalpublic2007-09-05 20:442007-09-06 04:21
Reportermottl 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version3.10+dev 
Target VersionFixed in Version3.10+dev 
Summary0004382: Strange typing restriction with polymorphic record fields
DescriptionIn 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.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0004144)
garrigue (manager)
2007-09-06 04:21

Fixed by avoid polymorphic fields in Typecore.build_as_type.

- Issue History
Date Modified Username Field Change
2007-09-05 20:44 mottl New Issue
2007-09-06 04:21 garrigue Status new => closed
2007-09-06 04:21 garrigue Note Added: 0004144
2007-09-06 04:21 garrigue Resolution open => fixed
2007-09-06 04:21 garrigue Fixed in Version => 3.10+dev


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker