[<<][meta][>>][..]
Tue Dec 6 14:22:45 EST 2011

Mile stone

Now that _lambda and _app use explicit data structure built with Atom
and Cons everything seems to infer just fine.  It's probably possible
to write some wrappers on top of these to hide this tagging and work
directly with Haskell tuples.  Maybe even explicit wrapper that
implement 1,2,3,... args for curried functions directly.  I.e. I want
to automate this:


app1 f a1       = _app f (Atom a1)
app2 f a1 a2    = _app f (Cons (Atom a1) (Atom a2))
app3 f a1 a2 a3 = _app f (Cons (Atom a1) (Cons (Atom a2) (Atom a3)))

lam1 f = _lambda $ \(Atom a1) -> f a1
lam2 f = _lambda $ \(Cons (Atom a1) (Atom a2)) -> f a1 a2
lam3 f = _lambda $ \(Cons (Atom a1) (Cons (Atom a2) (Atom a3))) -> f a1 a2 a3

The thing which is different that before is that the return type is
not so relevant.  It's only a single value, i.e. an exit code.  All
the rest should be computed with side effects

An important point seems to be that the language has only 1 lambda and
app form, both taking a single argument.  If we want different
lamba/app forms, this would probably be implemented as a type class on
top of Loop.

So.. I can get to the base case.  


class LoopLam arg res fun | res -> fun, fun -> arg res where
  lam :: (arg -> res) -> fun
  
class LoopApp arg res fun| res -> fun, fun -> arg res  where
  app :: fun -> (arg -> res)

-- lam1
instance (Loop s m r,
          StructPrim s r a,
          StructRepr r)
         => LoopLam (r a) (m (r t)) (m (r (Atom a -> m t))) where
  lam f = _lambda $ \(Atom a1) -> f a1
    
        
-- app1
instance (Loop s m r,
          StructPrim s r a,
          StructRepr r)
         => LoopApp (r a) (m (r t)) (r (Atom a -> m t)) where
  app f a1 = _app f (Atom a1)

How to write the recursive case?  It seems that I'm running into the
same problem here as before: Can't "unpack" that lambda.  It seems the
solution is to never pack it in the first place: it won't be the app
and lam that can be recursed, but the underlying apply and abstraction
ops.

Hmm.. let's be smarter about this.  The trick is probably to first
write the explicit lam1,lam2,lam3 in a recursive way.



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