[<<][meta][>>][..]
Sun Oct 23 10:55:49 EDT 2011

Encoding of loop

type I = Identity (Value Tint)
type B = Identity (Value Tbool)

t16 = f where
  f = _lambda $ \n -> do
    cond <- lt n (lit 123)
    n' <- mul n (lit 2)
    _if cond (_app f n') (_ret n)

t17 = _app t16 (lit 2) :: I

*Main> t17
Identity (Value 128)


Now of course this uses host-language code graphs, meaning that if
_app would build a data structure, and _lambda would too, this
structure would be cyclic.

So what is needed is a way to break the loop.  This needs a Y
combinator which can probably be disguised inside the letrec binding
form by inserting references.

Met de losse hand I come to this:

t18 = _letrec $ 
      (\f -> 
        _lambda $ \n -> do
          cond <- lt n (lit 123)
          n' <- mul n (lit 2)
          _if cond (_app f n') (_ret n))
      (\f ->
        _app f (lit 2))

It separates the definition of the functions with open recursion from
the creation of a context in which the functions can be used.

  _letrec :: (LoopPrim t, LoopFun m r f)
             => (r f -> r f)     -- body with open recursion
             -> (r f -> m (r t)) -- scope with functions defined
             -> m (r t)

Cool.  That was the next milestone.

Looks like this part is done except for handling tuples better, both
for arguments and parallel letrec bindings.

I'm curious though how this wil interact with the node naming monad..



[Reply][About]
[<<][meta][>>][..]