Wed Aug 31 20:30:30 CEST 2011


The trick is the following: the only thing I don't know (and don't
care about) in practice is the form of the container (nested pairs)
because it will be flattened into a list.

In practice, when compiling I do know what the base terms are, so
compiling will probably not effectively loose any information, just
the static types which are no longer necessary because the output data
(language syntax) is already in the required form.

So let's start out with a class that expresses this: a state object is
composite, and has an interface that allows enumeration and gathering
into lists of a certain type.  Is this a standard interface?

So the idea is to convert:

  stateShow :: s -> [String]

to something more like

  stateShow :: s -> [p]

where p is another parameter that represents the primitive state type.
The default implementation could then be p = String.

The trouble I had before was to get the following to typecheck (with
stateShow renamed to statePeek) :

  instance (SigState a p, SigState b p) => SigState (StateProd a b) p where
    stateIndex n0 (StateProd (a, b)) = (n2, (StateProd (a', b'))) where
      (n1, b') = stateIndex n0 b  -- Align numbering with causality through composition
      (n2, a') = stateIndex n1 a
    statePeek (StateProd (a,b)) = statePeek a ++ statePeek b

I got it to work, but I needed UndecidableInstances because of:

       the Coverage Condition fails for one of the functional dependencies;
       Use -XUndecidableInstances to permit this