3 ms·
Obviously at some point you need to get something done. The question is how you organize your data and your actions.
by dllthomas 13y ago
Obviously at some point you need to get something done. The question is how you organize your data and your actions.
- taeric 13y agoNot sure I follow. I'm essentially asking how this question is addressed with the single word answer of "functionally." I think a lot of this comes from the terrible division of "layers" that we have introduced in most common metaphors. Often we have to go through gymnastics to get all "mutations" back to a base layer where we can view them as "events" and then have pure functions that operate on these events. Consider, the common division of "Storage, Logic, Display" that we try and hammer out in some form or fashion. It becomes all too often that one can not come up with a good way of describing these systems where events only propagate along a single direction in these layers. As such, we often find small silos of "storage" in the logic and display area. (Similarly, we have a small silo of "logic" in both storage and display, quite often.) Coming up with a mechanism where there is a single "storage" location for an entire application often introduces complicated logic. Carmack had an interesting take on this idea for games programming, where the current logic "state" would be held immutable such that all calculations were only allowed to work on the current state. Kept those calculations easier, but introduced a new layer of effort to make that possible. Now, I think his argument was that this layer of effort could be seen as almost a constant factor that has shrunk in cost compared to the scaling cost of the number of actors involved in a modern system.
- dllthomas 13y agoWell, take that Logo procedure. If all I want to do with that list of commands is execute them, then a fully imperative language (like, as best I recall, Logo) is fine. Once I want to do slightly more complicated things (say, repeat) you need to move beyond "simple list of things". Of course, for a lot of things you might want to do to a list of commands (obviously including repeat) there is built in support. But what about when you want to define new ones? "Do each thing in the following list twice"? In Haskell, if you're passing around [IO ()], you can run it through (concatMap (\ x -> [x,x])) before passing it to sequence, and bam - things are doubled.
- taeric 13y agoNot sure I really follow. Every example you gave is just as intuitive in an imperative form as it is otherwise. Likely more. You want to teach someone how to do a dance? Teach them the few basic steps, and then start showing them how to interlace said steps. Hell, ever looked at the instructions for making your clothes? They speak in the language of seams and stitchings, yet are able to put together a whole clothing quite nicely. Even have room to adjust to things going wrong such as a thread or needle breaking during the process. (This is one area where exceptions have always seemed to me that they should be the continuation use case. Keep going until you hit an exception, fix the cause, then continue from where you left off.)
- dllthomas 13y agoI don't think you did follow. Nothing stops you from listing actions, in any language. In a language where actions are executed just by being listed unless particular magic constructs are used, you are more limited with what you can do with sequences of actions. Again, try to write something in logo that takes a list of arbitrary actions, and runs through the list executing each action twice before moving on to the next.
- taeric 13y agoBut isn't this already solved in an OOP world? So long as your "list of actions" is against a target (the "metaphor" in my original post), you can accomplish what you are referring to by manipulating that target. To go with my dance suggestion: function dance(dancer) { dancer.stepForward dancer.crossStepForward dancer.crossStepForward } Now, before the dancer is passed to this function, it is first passed to a "goOnPoint" function, such that now those directions are taken while on point. Or a "do all steps twice" function, for your direct example. The cooking metaphor is a little more directly applicable here. The cook is just configured to double (or half, etc) all ingredients used. Heck, the cook can even be configured such that substitute ingredients are known. Consider, it is trivial to use soy milk instead of regular milk for many "recipes". I actually like that example, because it doesn't always work. In a sense, it doesn't "type check." Some recipes have to basically be flagged as "milk substitutes not applicable." I fail to see how a monad really helps there.