Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006314OCamllanguage featurespublic2014-02-02 13:492017-03-01 15:38
Assigned Togarrigue 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0006314: Allow "functional record update" for objects
DescriptionWith records, one can functionally update a field e.g. as

{ r with some_field=new_value }

And new_value may, of course, be a function.

The request is for similar functionality for objects.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
jpdeplaix (reporter)
2014-02-02 22:25

I agree, this would be useful.
garrigue (manager)
2014-02-03 14:45

What you are asking for is not completely clear.

The simple one (and closest to functional update) would be to allow just to override methods externally.
I.e., you just build a new immediate object forwarding most calls to the original object, and redefining some methods (but not visible from the original ones). Actually this is just a kind of syntactic sugar, but requiring to know the type of the object.

Another meaning would be to copy the object, changing the method table.
Doable too, but rather different, as in this case the state is not shared.
Moreover this require that methods have exact types: this would be unsound if methods were allowed to have subtypes in subclasses (as per the Abadi-Cardelli book).

Finally you might want to update the method table of the current object. But in that case this is destructive update, not functional, and this would break completely the semantics.

Also, for soundness reasons, in none of this case you would be allowed to access value fields from newly defined methods (they do not appear in the object interface).
tom.j.ridge (reporter)
2014-02-03 14:54

Without knowing much about objects, I believe I am asking for

"The simple one (and closest to functional update) would be to allow just to override methods externally."

But, the scenario I am in means that I don't know exactly which methods are available on the object (but I know one method that is - the method I want to override). This means that I can't just make a new object (with methods delegating to the old object except for the "updated" method).

I *think* this makes semantic sense, but I'm not sure.
tom.j.ridge (reporter)
2014-02-03 15:00

Also, it would be super-useful if there was support for adding in new methods e.g.

{{ myobj with some_new_method=some_fun }}

if this makes sense.

- Issue History
Date Modified Username Field Change
2014-02-02 13:49 tom.j.ridge New Issue
2014-02-02 22:25 jpdeplaix Note Added: 0010873
2014-02-03 14:45 garrigue Note Added: 0010874
2014-02-03 14:45 garrigue Assigned To => garrigue
2014-02-03 14:45 garrigue Status new => feedback
2014-02-03 14:54 tom.j.ridge Note Added: 0010875
2014-02-03 14:54 tom.j.ridge Status feedback => assigned
2014-02-03 15:00 tom.j.ridge Note Added: 0010876
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-01 15:38 doligez Category -OCaml general => language features

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker