Sun Oct 23 15:51:52 EDT 2011


Trying to implement _if I'm wondering if I'm not doing something wrong
here.  It seems that the computation is split.  Does this correspond
to forking the variable generation?

Something isn't right with my intuition here..  Or my intuition's
right that it's wrong :)

Maybe I should start with writing a different returnN and let it build
Expr forms instead of Env?  Env can be fully captured with the Let
form only.  LetRec, If, App then do flow control.

Does it matter that If only references procedure calls?  Maybe not a
good idea since it's quite OK to represent If in C.

This needs a zipper.  At any point it needs to be clear what the
lexical context is, and for that we need to turn the Expr inside out.
The monad is then the zipper + variable naming state.

( I already had a zipper: the Env was "reversed" before. )

So there are 2 parts here: connecting up the monad data structure, and
evaluating it using a zipper.

It probably takes a form like this:

 c' <- nameVar c
 y' <- nameBlock y
 n' <- nameBlock n
 return $ If c' y' n'

It's not sure if nameBlock acktually needs to do naming..  It might
just pass the expression, but do some other bookkeeping on the side,
like updating the variable generation store.

An nameVar might have been done earlier also..

Actually, it's probably more like this:

_if c y n = do
    y' <- y
    n' <- n
    return $ If c (return y') (return n')

The two bind forms ensure that the CPS monad has "passed through" the
subexpressions.  Actually.. why do I think that If takes a monadic
argument?  It doesn't.  Once in syntax land (the If constructor) It's
really just values:

_if c y n = do
    y' <- y
    n' <- n
    return $ If c y' n'

Actually, that's the case after taking into account the wrapper that
implements the phantom type:

_if (Code c) y n = do
    (Code y') <- y
    (Code n') <- n
    return $ Code $ If c y' n'