Mon Aug 1 11:41:51 CEST 2011

Struggling with SC monad

Trouble is that the Show,Eq,Integral,... type classes are required.
I'm doing something wrong because it seems that the semantics need to
be more general.  Can these be CPS-ified also?

I don't know what I'm doing..  It's too abstract.

The funny thing is that some form of "local-consistency" reasoning can
help to get the code right, and then when it's finally there you can
"interpret" the composition.  This is a _strange_ way of working!

So what is the core problem?

It's juggling the types.  I got this to work, which I find surprising:

type Dict = [(String,String)]
type Res  = (String,Dict)
returnN :: String -> SC Res Dict String

returnN x = SC c where
  c d k = k d' v where
    v = "R" ++ (show $ length d)
    d' = (v,x):d

data SSA t = SSA (SC Res Dict String)

ssa2 fn (SSA x) (SSA y) = SSA $ do 
  vx <- x
  vy <- y
  returnN $ concat ["(",fn," ",vx," ",vy,")"]

The awesome bit here is that the state-contiuation monad is completely
behind the scenes, meaning the monadic parameter (which is a String!)
is not the same as the t parameter of SSA: t is fake!

The threading performed by the SC monad is at the heart of things: the
function that implements 2-op composition.


This blows my mind.

*FinalSSA> 1 + 2 + 3 + 4 :: SSA Tfloat
("R2",[("R2","(fadd R1 4.0)"),
       ("R1","(fadd R0 3.0)"),
       ("R0","(fadd 1.0 2.0)")])