-
Notifications
You must be signed in to change notification settings - Fork 19
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
What exactly set(obj, f, val) means? #157
Comments
I expect from In some cases like In other cases like your examples, there is no unique natural decomposition. In these cases, it is best to make clear what is happening, by documentation, comments, more explicit names. In your example, I would have no expectation of what |
Yeah, that part is clear – but I don't think lens laws specify what happens to the part of
With fields/properties/collection indices there's this natural decomposition, true. I think Accessors do a good job at preserving it! Maybe, the only right answer here is that one needs to think carefully when defining function setters, to ensure there's a natural "orthogonal" decomposition. I found myself with a more involved case of this "ellipse example", where I defined several setters to do whatever appeared natural at different times, and found out they aren't quite consistent. Unfortunately, doesn't seem like there is a way to programmatically test this kind of properties, they are hard to even define in text. Do you happen to know of solutions in "stricter" languages like Haskell/Scala/... ? |
I don't know about other languages. One approach to make the decomposition used obvious would be something like: @set Ellipse2(ellipse).minor_major_ratio = ...
@set Ellipse1(ellipse).minor_radius = ... More mathematically this makes explicit the isomorphism used between |
The question may sound strange, but what exactly
y = set(x, f, val)
means/supposed to mean?The contract specifies that
f(y) == val
, but what about other parts of the object?Consider this hypothetical scenario:
What should
set(ellipse, minor_axis, val)
do: keep the ratio or the major axis constant?Same question for
set(ellipse, minor_major_ratio, val)
: does it keep major axis? Minor? Average?..Should it be the same or different for Ellipse1 vs 2? If one implements set() based on the implementation (internal fields) of these objects, it will result in a weirdly different set() behavior for two ellipse types that are otherwise treated equivalently.
The text was updated successfully, but these errors were encountered: