Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007534OCamllanguage featurespublic2017-05-18 10:272017-05-27 02:37
Reporterfrisch 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityhave not tried
StatusnewResolutionopen 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0007534: Extensible record types
DescriptionWe already have extensible sum types. What about adding extensible record types? This might be very useful to represent "property bags" in an efficient way.

This could look like:

  type t = { .. }
  type t += { x: int = 0 }
  let x : t = { }
  let y : t = { x = 42 }
  let f (r : t) = r.x
  let g (r : t) = {r with x = 42}
  let h : r -> int = function {x; _} -> x

  module M : sig type t += {x: int} end = struct type t += { x: int = 0 } end
  module N : sig type t += {x: string} end = struct type t += { x: string = "" } end
  let r = {M.x = 42; N.x = "hello"}


On the implementation side:

 - Each extension label could be represented as a block with Object_tag (as for extension constructors), also holding the default value.

 - An extensible record value could be represented roughly as an object where the index of fields in the "vtable" would not be obtained by hashing the name, but using directly the unique integer stored in the extension label block. We would reuse the existing machinery for caching lookups.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0017803)
lpw25 (developer)
2017-05-18 11:49

Since you bring it up I had a design for this lying around in some notes somewhere. It follows pretty closely with what you suggest (even using the same syntax). The main difference was that it was mixed with a notion "optional label", so in addition to the "default argument" style of your proposal:

  type t += { x: int = 0 }
  r.x
  function {x; _} -> x

it also supported:

  type t += { ?y: int }
  r.?y
  function {?y; _} -> y

with

  r.y

as short-hand for:

  (let { ?y = Some y' } = r in y')

(including the ensuing warning -- I include it for syntactic consistency rather than usefulness)

and

  function {y; _} -> y

as shorthand for:

  function {?y = Some y} -> y

- Issue History
Date Modified Username Field Change
2017-05-18 10:27 frisch New Issue
2017-05-18 11:49 lpw25 Note Added: 0017803


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker