Mon May 20 08:49:35 EDT 2019
Memory is coming back, painfully :)
Cliche, but this is more difficult than I thought it would be. It's
near obvious what it _should_ be when going through the motions, but
performing the assembly requires a lot of small refinement steps.
So let insertion works. Next is loop nesting. This will require some
loop $ \i -> do ...
I think the state continuation monad is too simple: it does not return
the final value of the state, and it appears as if an entire
computation needs to be run as a subprogram.
I wonder if the trick is to just embed the state in the return value
of the expression?
No this is actually not possible because "return" cannot excape the
context. So it really needs to be part of the type.
Let's look at the original paper to see what the type is.
This was a problem before:
-- Note: state will be forked! The Let insertion mechanism doesn't
-- allow recovery of state.
mBlock :: MCode (Code t') -> MCode (Code t)
mBlock sub = SC main where
main s k = k s $ Code $ (subTerm s sub)
Ok so I need a version of the SC monad that threads state through the
entire computation. Maybe that isn't possible?
Actually it is possible to get the state by just tagging it, but it
will dump it deeply nested inside the data structure.
I'm missing an essential insight.
So let's implement it first with a state fork, then see what would be
necessary to patch it up.