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
Allow "functional record update" for objects #6314
Comments
Comment author: jpdeplaix I agree, this would be useful. |
Comment author: @garrigue 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. Another meaning would be to copy the object, changing the method table. 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). |
Comment author: tom.j.ridge 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. |
Comment author: tom.j.ridge 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. |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
Yes, the first semantics proposed by @garrigue seems like the way to go, and it sounds not too hard to implement. We haven't spent much effort lately improving the object system (which makes sense given how little it is used by most OCaml projects), but the feature still makes sense and we can easily see how it would be useful for some use-cases (both to override or to extend). (This goes back to a more general discussion about whether we should have polymorphic records, or make objects easier to use as polymorphic records.) |
I suppose that this means having polymorphic operations of the form:
that actually update the virtual table. Adding a method would be harder, and cannot be done polymorphically (i.e. that would actually be type-directed syntactic sugar). |
Just for fun here is an implementation of functional update.
|
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
Original bug ID: 6314
Reporter: tom.j.ridge
Assigned to: @garrigue
Status: assigned (set by tom.j.ridge on 2014-02-03T13:54:45Z)
Resolution: open
Priority: normal
Severity: feature
Category: language features
Monitored by: @gasche @hcarty @alainfrisch
Bug description
With 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.
The text was updated successfully, but these errors were encountered: