I have a problem that I don't know how to reason about. I was just about to ask if somebody could help me with the specific problem, but it dawned on me that I could ask a more general question and hopefully get a better general understanding as a result. Hopefully. So here goes:
It's usually obvious enough when your program is too lazy, because you end up with glaring issues like space leaks, for example. I have the opposite problem: my program is too strict. I am trying to tie knots, and find that certain things I attempt to do will somehow defeat the laziness I need. So my general question is, how does one debug unwanted strictness?
For completeness, here's my specific case: I'm in RWS
, where the writer component populates a map, and the reader component observes the final state of that map. I can't do anything strict with this map before I've finished populating it. It appears to be no problem to look up values in the map, like:
do
m <- ask
val <- m ! key
doSomething val -- etc.
But (!)
fails using error
, where I'd instead prefer to fail using my monad's fail
. So I'd like to do something like the following:
do
m <- ask
maybe
(fail "oh noes")
(doSomething)
(lookup key m)
This causes my program to <<loop>>
, which I don't understand. It doesn't seem to me like this should be any more strict than using (!)
, but obviously I'm wrong...
RWST
'sfail
. – Intellectualize(!)
- what if I were to layerMaybeT
on top of myRWS
? – Intellectualize