[<<][meta][>>][..]
Sat Oct 29 12:38:18 EDT 2011
Lambda problem
It seems that I'm confusing the operation types.
insertLet :: r t -> m (r t)
but what I have has an extra computation argument that needs to be
properly sequenced.
insertLambda :: [t] -> m (r t) -> m (r t)
the 2nd argument is the body, while the first is the arguments.
Can this sequencing be done with bind? I don't see how, so let's do
it manually. I end up with this as first attempt:
insertLambda vars (SC cBody) = SC cTerm where
cTerm s k = k s' $ Lambda vars body where
(s', (Code body)) = cBody s (,)
To obtain the body term. the whole cBody computation has to be
executed. The state output of that computation is then reused; body
probably did some variable allocation.
What I don't undersetand is the type:
insertLambda :: [Var] -> SC s (s, Code t) (Code t) -> SC s r Term
This might be problematic, as the return type of the computation is
(s, Code t) instead of Term. Let's see.
Indeed:
Couldn't match expected type `(TML.CompState, Code t0)'
with actual type `Term'
So is there a way to avoid this by not running the computation
directly, but by chaining it into the other using CPS? Something like
this:
insertLambda vars (SC cBody) = SC cTerm where
cTerm s k = cBody s k' where
k' s' (Code body) = k s' $ Code $ Lambda vars body
Yep it looks like that was it:
> t14
(Let (Var i "t2" 0) (Lit i "1")
(Let (Var i "t3" 0) (Lit i "2")
(App
(Lambda [Var i "t0" 0,
Var i "t1" 0])
(Ret (Ref (Var i "t0" 0))))
[Ref (Var i "t2" 0),
Ref (Var i "t3" 0)])))
[Reply][About][<<][meta][>>][..]