[<<][meta][>>][..]
Fri Dec 30 09:53:35 EST 2011

Simpler tests for SArray

So.. Maybe the SArray declaration is just simply meaningless?  These
errors are so strange...

  b19 (L arri) = do
    xs <- _get' arri (lit 0)
    (L x1, L x2) <- _unpack xs
    x <- add x1 x2
    y <- add x (lit (1 :: Tfloat))
    _ret y
  f19 =   _def "fun" $ _lambda b19 
  t19 = ctop $ term $ f19

  /home/tom/meta/dspm/0test_TML_Sys.hs:406:21:
      No instances for (Struct Term Code t2'0 (L Tfloat),
                        Struct Term Code Double (Code Double))
        arising from a use of `f19'
      Possible fix:
        add instance declarations for
        (Struct Term Code t2'0 (L Tfloat),
         Struct Term Code Double (Code Double))
      In the second argument of `($)', namely `f19'
      In the second argument of `($)', namely `term $ f19'
      In the expression: ctop $ term $ f19
  Failed, modules loaded: Type, Array, TML, Sys, Term, Code, Loop, Struct, PrettyC, StateCont, SArray.


The "Struct Term Code Double (Code Double)" part makes no sense.  This
is probably a non-tagged leaf node.  This should never occur.  Only
the following instance should, which is defined:

    Struct Term Code (L Double) (Code (L Double))

I tinkered the type class constraints a bit, removing the Struct
constraints to end up with this:

  -- Base case delegates to Array instance.
  instance (TMLword t,
            Array m r a t,
            StructRepr r,
            Loop stx m r) 
           => SArray stx m r (L (a t)) (L t) where 

  -- Inductive case.
  instance (Array m r a st1,
            Array m r a st2,
            SArray stx m r sat1 st1,
            SArray stx m r sat2 st2,
            StructRepr r,
            TML m r)
           => SArray stx m r (sat1, sat2) (st1, st2) where

Then the following example compiles:

  b19 (L arri) = do
    xs <- _get' arri (lit 0)
    (L x1, L x2) <- _unpack xs
    x <- add x1 x2
    y <- add x (lit (1 :: Tfloat))
    _ret y
  f19 =   _def "fun" $ _lambda b19 
  t19 = ctop $ term $ f19

But running it I get the error that uncons is not implemented for
Code.  This is weird.  I conclude that Term support is going to be
necessary anyway.

Man this is over my head..
Interesting though.

So, I officially don't know what I'm doing.  Let's see where this
leads to.  I expect that the two approaches I've been describing are
going to be equivalent and that yest, there is something in Term that
needs to encode the intermediates of the _get' operation.

Ok, it gets interesting.  I've added the following which is what I
thought it would be + an error clause to see what causes the
unexpected match error:


  instance StructRepr Code where
    atom (L (Code a))        = Code (Atom a)
    cons (Code a, Code b)    = Code (Cons a b)
    nil  ()                  = Code Nil

    unatom (Code (Atom a))   = L (Code a)
    uncons = uc where 
      uc (Code (Cons a b)) = (Code a, Code b)
      uc (Code x) = error $ show x
    unnil  (Code Nil)        = ()


The match error is:

  *** Exception: 
  Ref (Var {varType = Type (AStruct [Type AFloat 1,
                                     Type AFloat 1]) 0, 
            varName = "a0"})

Meaning that the Term is a varref.  What does this mean?

It seems to hint that the implementation for StructRepr can be made
completely virtual after all..  All this is is phantom types that are
eventually resolved to something that's implementable.  (guess)

So.. This should be a variant of unpack.

It's becoming too abstract.

Anyways, let's try this route: use only virtual instances, don't do
anything with the contents.  See next post, this is really shotgun
programming..



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