2 ms·
You're conflating and confusing a whole ton of things, to the point where I don't really know where to begin... There is "monad as a mathematical concept", whi
by dllthomas 13y ago
You're conflating and confusing a whole ton of things, to the point where I don't really know where to begin...
There is "monad as a mathematical concept", which cookbooks don't "resort to" discussion of because a rigorous treatment of their internal logic isn't what cookbooks are about. A logician sitting down to describe and analyze the processes in a cookbook may well make reference to monads. Cookbooks don't care much about such description and analysis, because recipes are tremendously simple (compared to software), they rely on a ton of implicit knowledge, and they can be exhaustively tested.
There is "monad as an interface as it is used in Haskell", which cookbooks don't "resort to" because they are one particular DSL and the sole relevant context is implicit by the fact you opened a cookbook and are looking at something laid out like a recipe. It's not terribly difficult to characterize a recipe as a monad, though if you wanted to do so precisely you'd probably also want linear types (since you can't chop the same onion twice).
Regarding your later points of division of "imperative commands" and denotational constraints, I actually agree with you that splitting these but allowing some specification of both (I would actually broaden "imperative commands" to operational constraints generally) is going to be a worthwhile avenue in the medium to long term. I think, though, that it will look more like writing things out denotationally based on your actual goals (plus some operational constraints regarding time/space/resource bounds) and then filling in operational details as the compiler is unable to come up with how to do something on its own in a way that meets the requirements, as opposed to detailing how to do things and checking constraints.
- taeric 13y agoWhen I say "resort to" it just strikes me how in programming today we are going out of our way to throw these constructs up in the face of the programmer. That they could be used to describe what is happening, I do not argue. That they are more rigorous, I also do not argue. That they universally help people reason about things, I do argue. And this is the second time that linear types have come up in this thread. They do seem like what I want, but I want more "state." That you can only dice an onion once, does not prevent me from still referring to that as "the onion." Ideally, I would want a variable where the specific type is altered and checked at each occurence. In the imperative world, the progression of time would make dictate what state/type is relevant at any given point.
- dllthomas 13y agoI think a part of it is that you're restricting the discussion to examples too small to be meaningful. Does the fact that IO forms a monad help us, when all we're doing is sequencing actions in a static order without interesting interactions? No, not really. It also doesn't hurt. main = do let dry_ingredients = [ (Flour, 10) , (Sugar, 5) ] butter = (Butter, 1) eggs = (Egg, 2) pan = CakePan oven_heating_task <- heatOven XXX bowl_contents <- withBowl $ do mapM_ add dry_ingredients mix add butter whip add eggs waitFor oven_heating bakeInPan pan bowl_contents You don't even really have to understand monads to follow the above code. They also don't do much to improve it over ordinary imperative code. (They arguably do quite a bit to improve it over the "lazy streams of requests and responses" approach that early Haskell took...) Where functional style and a robust type system becomes a huge win is in larger programs - and, in particular, significant refactors of larger programs. If you've done a few of these in a few contexts, you should have a good sense of why.
- taeric 13y agoOh, certainly there is a large aspect of "the problem is simply the examples." I have yet to see a compelling system built in the functional style, is the problem. It is tempting to feel that there is this holy grail where this becomes a big win. I even can "intuitively" see how this would be true. However, what I also experience is that this 'win' seems countered by the 'loss' in just how much cognitive overhead goes in to building said large system. That is, sure, it can be modified with more confidence, but was it ever fully built? (I think this comes from the caveat shown in upthread paper where, to stay truly transparent the developer winds up having to account for the entire state of the system at some layer.) Even looking at my own examples where I was somewhat proud of the amount of information that was in the type system, I can not honestly claim that the product was more bug free than loosely typed version, and it certainly wasn't more clearly communicated to my peers. (Including my future self.) In the end, smaller more directed pieces using whichever styling makes the most sense for that section seems to be the clearest win. Edit: Apologies for the quick edit, but I am also struck by just how well the "literate" programs I have ever read actually worked at communicating what was going on. Shame that seems to have stalled to death.