Thu Aug 13 10:44:11 EDT 2015

SysState, StateFB, StateFold

Renamed and put in different module since it's used in Siso and Sig.

Now, what would StateFB be?  Is there a simpler way to express the

Probably, but currently having separate stateIn / stateOut seems most

Actually, this might be simpler:

       s -> s -> m (s, t) -> m t

The existence of such a method also implies that somehow state is "not
there".  I.e. it would abstract the natural fold that can already be
done without knowing anything about the type.

But let's fix this after moving to Sig as main representation.

EDIT: trying this in:

appSys (Sys stateInit update) = do
  i <- makeVar >>= fun
  stateFold stateInit $ (flip update) i

Which has the effect of placing the state generation inside the
function instead of outside.  Shouldn't be a problem, so I'm just
going to change stateFB to stateFold.


It actually seems quite important to make this abstract, i.e. just use
stateFold, not stateIn, stateOut.

However, I find it difficult to write a StateFold instance for (,).

Somehow I can't "split" f.  It should be the inside-out of this:

  stateFold (i1, i2) f = mt where
    f' (s1, s2) = do
      t1 <- stateFold i1 s1
      t2 <- stateFold i2 s2
      return (t1,t 2)

This looks like it needs knot-tying, something I'm not too familar

Or there's another trick.

I have

   (s1,s2) -> m ((s1,s2), t)


   s -> (s -> m(s, t))

for s1 and s2, and for any t.

The trick is probably to tunnel one of the functions through t.