[<<][meta][>>][..]
Sat Oct 29 10:41:53 EDT 2011

Infer multi-arg functions

Inference doesn't work properly, but manual annoation seems to work:

f2 :: (StructPair (,) r,
       StructPrim s (r a),
       Monad m,
       Loop s m r)
      => m (r ((a,a) -> m t))
f2 = _lambda $ \(a,b) -> do 
  f <- f2
  _app f (b,a)


Can we compile it?

One of the (undefined :: ras) variables got evaluated in the tuple
pattern matching, so I changed the following implementation to ignore
the inputs, and reconstruct new undefined values:

hunk ./dspm/Loop.hs 112
-  structSize (r_as, r_bs) = structSize r_as + structSize r_bs  [_$_]
+  structSize _ = structSize (undefined :: r_as) +
+                 structSize (undefined :: r_bs)
hunk ./dspm/Loop.hs 115
-  structVariables ns (r_as, r_bs) = ((a,b), ns'') where
-    (a, ns')  = structVariables ns r_as
-    (b, ns'') = structVariables ns' r_bs
+  structVariables ns _  = ((a,b), ns'') where
+    (a, ns')  = structVariables ns  (undefined :: r_as)
+    (b, ns'') = structVariables ns' (undefined :: r_bs)

Next problem is that without letrec, this produces an infinite data
type:

t11 = termCompile (f2 :: C2)

So let's try tupling first.  Seems to work.  I did have to annotate f7
to make it type check.


f7 :: (StructPair (,) r,
       StructPrim s (r a),
       Monad m,
       Loop s m r)
      => m (r ((a,a) -> m a))  
f7 = _lambda $ \(a,b) -> _ret a

type C2 = MCode (Code ((Tint, Tint) -> MCode Tint))

t13 = termCompile (f7 :: C2)


> t13
Lambda [Var i "t0" 0,Var i "t1" 0] (Ret [Var i "t0" 0])


I noticed that pack/unpack and thus cons/uncons are not used for Code
instance, but this seems not correct: _app probably needs it.  Check this.

Actually, _app uses structPack while it can probably use structCompile.

( Are these cons/uncons and structXXX actually special cases of the
same interface?  They do seem to behave in a similar way.. )

So _app for Code indeed works without _cons / _uncons.

For the test to run it makes sense to have more general application.
I'm also changing Term in this way:

-            | App    Fun [Var]                -- function application.
-            | If     Var Term Term            -- conditional branching
-            | Ret    [Var]                    -- invoke toplevel continuation

+            | App    Term [Term]              -- function application.
+            | If     Term Term Term           -- conditional branching
+            | Ret    [Term]                   -- invoke toplevel continuation



Still getting botched lambda insertion..

t14 = termCompile $ do
  f <- (f7 :: C2)
  l1 <- insertVar $ lit 1
  l2 <- insertVar $ lit 2
  _app f $ (l1, l2)

> t14
Lambda [Var i "t0" 0,
        Var i "t1" 0]
  (Let (Var i "t2" 0) (Lit i "1")
  (Let (Var i "t3" 0) (Lit i "2")
    (App (Ret [Var i "t0" 0])
         [Ref (Var i "t2" 0),
          Ref (Var i "t3" 0)])))



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