[<<][meta][>>][..]
Mon Jan 2 08:29:50 EST 2012

_lambda type

Why is the argument in _lambda a packed struct, i.e. r (L t) instead
of an unpacked one, i.e.  L (r t)?

This might be the problem.  In Loop it's clear it should be the latter
(struct of representations identified by 'sr' type variable.
  
  _lambda :: (TMLword s,
              StructVar stx sr,  -- var name generation.  FIXME: can this be removed?
              Struct r s sr) 
             => (sr -> m (r t))
             -> m (r (s -> m t))

In loopExpr2 this is the same:

*Main> :t loopExpr2
loopExpr2
  :: (Loop stx m r,
      Array m r a as1,
      Array m r a s,
      Array m r a t2,
      TMLword as1,
      TMLword s,
      TMLword as,
      TMLword t2,
      StructVar stx (L (r Tint)),
      StructVar stx t1,
      StructVar stx t,
      Struct r as t,
      Struct r s t1,
      Struct r as1 sr1,
      Struct r t2 sr) =>
     (L (r (a as1)), ((L (r (a s)), L (r (a t2))), L (r Tint)))
     -> ((t, t1) -> m (sr1, sr))
     -> r ((as1, L Tint) -> m Tint)
     -> m (r ((as, L Tint) -> m Tint))

The base type of the state array (r (a as1)) is the same as the
argument of the embedding function  r ((as1, L Tint) -> m Tint)

This means that as1 is a struct of representations.  Or what?  No.
Following the definition of _lambda above, the representation for a
function is indeed (r (s -> m t)) which is implemented in terms of
something using struct of representations (sr -> m t).

So this is correct.  Both as1 should really be the same.

First strange thing, in this:
   
  loopExpr3 :: (Loop stx m r,
                TMLword s,         -- s can be represented in the target (as a C structure)
                Struct r s sr,     -- s can be represented in the host ..
                StructVar stx sr,  -- .. and it's rep can be deconstructed in variables
                StructVar stx (L (r Tint))
                )
               => (L (r (a s)), ((r pi, r po), L (r Tint)))
               -> ((sr, i) -> m (sr, o))   -- update is HOS: it works on struct of rep
               -> r ((s, L Tint) -> m Tint)
               -> m (r ((s, L Tint) -> m Tint))

It wants to (s ~ sr) Ok, this is because the loopbody is indeed type
sr, not s.  The rest was straightforward:



  loopExpr3 :: (TMLword s,         -- s can be represented in the target lang (C structure)
                Struct r s sr,     -- s can be represented in the host lang
                StructVar stx sr,  -- .. and it's rep can be deconstructed in variables
                Array m r a s,     -- s is provided in an array (singleton array == box)
                Struct r i si,     -- relation between rep of struct and struct of rep ..
                Struct r o so,     -- .. for input and output
                TMLword i,         -- i,o can be repd in target lang
                TMLword o,
                StructVar stx si,  -- si, so can be repd in host lang
                StructVar stx so,              
                SArray m r i pi si srai,  -- i,o are in "transposable" struct of arrays
                SArray m r o po so srao,
                StructVar stx (L (r Tint)),   -- the loop index is a host-repd struct
                Loop stx m r)      -- relation between host and target language
               => (L (r (a s)), ((r pi, r po), L (r Tint)))
               -> ((sr, si) -> m (sr, so))
               -> r ((s, L Tint) -> m Tint)
               -> m (r ((s, L Tint) -> m Tint))

The last thing added was the SArray instances.  The variables srai and
srao are not used so they might be cause of trouble.

The error later down the line is still:

  *Main> :t compile3 f2

  <interactive>:1:1:
      No instance for (StructVar Term (Code (L (Tint -> Tfloat))))
        arising from a use of `compile3'
      Possible fix:
        add an instance declaration for
        (StructVar Term (Code (L (Tint -> Tfloat))))
      In the expression: compile3 f2


What this means is that it wants to generate a representation of a
struct of an array type.

   r (L (a Tfloat))

Is this meaningful?  I thought it was not, that it should realy only be 

   L (r (a Tfloat))

but maybe it is actually..

Is there room now to investigate where this constraint comes from?

There's an error in the above.  It should be:

  (L (r (a s)), ((srai, srao), L (r Tint)))

instead of

  (L (r (a s)), ((r sai, r sao), L (r Tint)))

nope..  These are correct, but that probably means there is some extra
indirection there I'm not taking into account?

Woah this is confusing..

What about the difference between these two:

  (L refs, ((arri, arro), L arrn))

  (L refs, ((L arri, L arro), L arrn))
  
I'd think that because arri and arro are in direct correspondence to
target language elements, they should be leaf nodes.  Let's see if
this infers..

Yep, that was it!

Funny how some bugs are always in a different spot then where you're
actually looking.



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