-
Notifications
You must be signed in to change notification settings - Fork 15
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
Function Identity: Treating function items with identical bodies #1235
Comments
yes Is this worth it? (I'm cogniscant that if you ask an FPer about this, they shriek and say you're mad, and if you talk to an OPer, they say that methods are readonly, so you don't need to compare them, and 'functions' as objects, are comparable, but its not something they'd really expect anyone to do) |
I’m not exactly sure what you are proposing. Would you like to preserve the status quo (as described in #908)? |
I'm doing my usual irritating trick of trying to reverse the conversation 9 months, which is probably highly irritating, whilst you are trying incrementally improve the status quo. The way to stop me doing that (apart from telling me you're not willing to do it), is to give me motivating use case that I can't escape. I'm hoping this motivating use case though has an alternative approach that dissolves the problem of trying to (in an FPers view) solve the halting problem. OO'ers dissolve it, by defining equality inside the domain of the type, where all 'functions' are fixed (as methods) so the issue never arises (well not much). BUT...genuinely feel free to say..."its too late for that" |
It may not be too late for that, but you'll probably need to spend a lot of time to digest what has happened so far. With regard to your specific reply, I cannot really read out what you think may be worth or not worth doing. Could you be more specific? |
I was part of the conversation at one point, and tried to express my concern, I gave up (or was overpowered) but your summary isn't good reading, it unintuitive, and you appear to be saying results depend on what optimisations are turned on. the simple alternative (to allowing equals on functions) is "error" Whats the cost of that? i.e. what motivating use case does it stifle? and is enabling that use case worth the consequence of your summary table? is it just going to be bigger headache. the next simple alternative is "object identity" and all implementions have to respect it....its horrid...I hate functions having an identity, and if saw code comparing almost anything by object identity I'd feel concern. the next simple alternative is elevating some functions to "methods" only allowing equality inside a type (so you dont need to compare methods as they are statically defined), and not allowing equality for functions, so yes, you can compare objects in a type if all the fields are non functions, else....error. |
Thanks, I now understand you better: You would like to question the current concept of function identity in the specification general. I appreciate your concerns, but I think it is definitely out of scope here as I was focusing on the specific case that I think it’s better if you create a separate issue for your general concerns. Would that be ok for you? |
in the scope of this issue, my answer would be error and error :-) I wont raise it as an issue. Thanks for the offer, I don't think it would get traction. you don't need to reply, my response is just rhetorical. |
Thanks for your comments. For rhetorical feedback, though, I recommend you to join the discussions on Slack; my assumption is that it will be more productive for everyone involved. |
I'm sympathetic, but what exactly is your proposed fix? |
I would be happy if I could make a concrete suggestion. I have now understood how to interpret the current rules, but it would be presumptuous to say that I have grasped the interplay of all rules in full detail. Maybe it’s the rule in 4.5.2.7 Function Identity that should be changed. It says that: “An optimizer is permitted to rewrite expressions in such a way that repeated evaluation is avoided if it can be established that the result will be the same each time, […].” “Same result” seems to imply that two evaluated instances of Maybe we need to clarify what “same” means:
Without being able to provide a fix: Does my summary sound correct and reasonable? |
Perhaps rewrite the relevant paragraphs: An optimizer is permitted to rewrite deterministic expressions in such a way that repeated evaluation is avoided, and this may be done without consideration of function identity. For example, if the expression contains(?, "e") appears within the body of a for expression, or if the same expression is written repeatedly in a query, then an optimizer may decide to evaluate it once only, and thus return the same function item each time. Similarly, if the expression Similarly, optimizers are allowed to replace any expression with an equivalent expression. For example, count(?) may be rewritten as count#1, and Link to the definition of |
Thanks. Sounds good to me. Do you think there is a need to tweak the following rule further above in the text?
It could be argued that two deep-equal nodes with a different node identity are not identical (let alone results of nondeterministic expressions). Maybe the sentence after the semicolon could simply be dropped, or we might need to concretize what “identical” means in this context. |
(One) requirement resulting from #908 (in particular, #908 (comment)):
The following examples reflect the status quo:
deep-equal(<a/>, <a/>)
true
let $f := fn { <a/> } return deep-equal($f, $f)
true
deep-equal(fn { 1 }, fn { 1 })
true
orfalse
deep-equal(fn { <a/> }, fn { <a/> })
false
Notes
true
(regardless of the identity of the compared nodes).true
(regardless of the identity of the nodes that result from evaluating the functions)true
orfalse
, depending on the optimization strategies of a processor.false
.We should allow
deep-equal
to returntrue
for function items that have the same arguments and bodies. An implementation should be allowed to use the same internal representation for multiple occurrences of such functions.The text was updated successfully, but these errors were encountered: