3 ms·
A complete general implementation requires some kind of static notion of an "inverse", which is hard in turing complete languages. But really this is quite a bi
by adrusi 11y ago
A complete general implementation requires some kind of static notion of an "inverse", which is hard in turing complete languages. But really this is quite a bit like RAII for a lot of practical applications.
- rtpg 11y agoYeah, RAII helps encapsulate this pretty well at least for the object case, but the notion of having an "inverse" operation is useful in many other situations. An example I've run into a lot is wanting a generalized "toggle" for DOM actions in javascript (for example, show/hide), so if some property is true, I apply a transformation, and when the property is switched off I can apply the reverse easily. The trickiness with RAII (or things like context managers in python) is that it mainly works when you have a companion object representing the action (files are the companion object to getting handlers through opening/closing for example). But what is the object you could use for scaling? You can, of course, build a Scaler object (or MultiplierFactory ;) ), but I find myself wanting to avoid objects and methods to instead go for plain functions as much as possible.
- JadeNB 11y ago> A complete general implementation requires some kind of static notion of an "inverse", which is hard in turing complete languages. I don't think it's Turing completeness that's the issue (though it is an issue, of course) so much as non-invertibility. (I've always been fascinated by https://en.wikipedia.org/wiki/Reversible_computing https://en.wikipedia.org/wiki/Reversible_computing , but it doesn't seem, at least to my limited perspective, like it's the subject of much current research.) For example, what should the inverse of `(^2) :: Complex -> Complex` be?