2 ms·
> these cases (database transaction, writer) are things I do find it useful to manage with a monad. Yeah, I know, but some of us don't :) > You need some way
by pron 11y ago
> these cases (database transaction, writer) are things I do find it useful to manage with a monad.
Yeah, I know, but some of us don't :)
> You need some way to encapsulate/isolate the relevant state of a program partway through running
That's exactly what continuations do. The question of global mutable state is an orthogonal one.
> I think that state has to be equational if we're to have any hope of being able to understand programs - if you can't say whether this time at line 20 the program is in the same state it was last time at line 20, or a different state from last time, how can you even begin to debug?
Well, we have been successfully writing programs like that for a long time. Now, don't get me wrong -- the equational abstraction is often very useful, but it has its price, and it's not a complete representation of the computation.
> But will those approaches stop me from tripping myself up when effects don't commute?
I don't understand. We don't trip over ourselves when writing imperative code, and when we do, it mostly has to do with IO or other OS state, and monads won't help you there. Linear types ("typestate") might, but even they are limited.
- lmm 11y ago> We don't trip over ourselves when writing imperative code Speak for yourself. Though I guess I'm more concerned with refactoring than with writing. In particular in imperative code it's very hard to tell the difference between semantically important ordering and accidental ordering. > when we do, it mostly has to do with IO or other OS state, and monads won't help you there. Yes they will? It's very normal to encapsulate something of that nature with a monad.
- pron 11y ago> it's very hard to tell the difference between semantically important ordering and accidental ordering. Not when effects are clearly marked. There is zero difference in that respect between continuations (i.e. imperative) and monads. It's only syntax and whatever your type system is. > It's very normal to encapsulate something of that nature with a monad. Sure, but a monad won't help you ensure their proper ordering.
- lmm 11y ago> Not when effects are clearly marked. There is zero difference in that respect between continuations (i.e. imperative) and monads. It's only syntax and whatever your type system is. Well, my experience is that refactoring code with an explicit =/<- distinction is much safer than refactoring in the presence of Java checked exceptions. That's my argument against any "effectfulMethod(); effectfulMethod();" style. I find it hard to understand what the change (compared to monads) you're advocating is. If you want to make the evaluation of a function not a value, then what semantics does it have? (and surely however elegant they are, having different semantics for the return value and the effects of a given call is always going to be more confusing than finding a way to express both in the same model). > Sure, but a monad won't help you ensure their proper ordering. It does. You can offer only safe operations - e.g. because I can use a monad to compose a sequence of database operations and store that as a value, I don't have to expose "begin transaction" and "end transaction" operations, only a "do this operation (potentially a composition of several operations and/or pure computations) in a transaction" operation.