3 ms·
Fun! that would be cool, but I wonder how this would work if a func just returns 4 and then the number type was added, and then I change it to return "wow". Do
by pvinis 4y ago
Fun! that would be cool, but I wonder how this would work if a func just returns 4 and then the number type was added, and then I change it to return "wow". Do I have a type error or does my func type updates?
- nawgz 4y agoGood point. For this case, it's easy to imagine - such a construct would infer the function's new return type, and then any call-sites which have a mismatch would require updating. But you raise the real question of how the compiler could know when types were added by the inference-er versus the programmer
- gjm11 4y agoI think that if I were building a system that worked this way, automatically-inserted type declarations would be distinguished somehow (preferably in a way that in good text editors just appears as different formatting), and then when you change the function to return "wow" the compiler/linter/magic-type-annotator will see that the only things that need updating are ones it inserted itself, and just do it. If you edit any of those automatically-inserted type declarations, though, they're fixed and doing things that violates them becomes a type error rather than an auto-rewriting opportunity.