Mon Aug 3 13:43:08 EDT 2015


So, what about this:

r <- ramp
mul r r

it would be easy to see the duplication.

So this clearly means: copy the signals.

ramp2 = joinSys $ mul <$> ramp <*> ramp
*Test> compTest_I ramp2
state r0 : 0
state r1 : 0
  r2 = add[r0,1]
  r3 = add[r1,1]
  r4 = mul[r2,r3]
  r0 <- r2
  r1 <- r3

How to re-arrange things to reuse?

state r0 : 0
  r1 = add[r0,1]
  r2 = mul[r1,r1]
  r0 <- r1

So functionality is there.  The userinterface isn't though..
It it possible to use the monad for this?


square x = mul x x
ramp2'' = joinSys $ square <$> ramp

-- compSys ramp2'':
state r0 : 0
  r1 = add[r0,1]
  r2 = mul[r1,r1]
  r0 <- r1

So the trick is this: signals used in the Applicative <*> get
instantiated once for every use, but duplication in the lifted monadic
expressions is shared.

This seems most flexible, but also quite low-level.  What I want is to
have every variable be a signal, and essentially map a monadic scalar
program over them.

This boils down to wanting to introduce signals inside a monadic
scalar program.

I.e. something like:

\f1 f2 -> do
  x1 <- osc f1
  x2 <- osc f2
  add x1 x2
Where this would be equivalent to

\f1 f2 -> ( joinSys $ (\x1 x2 -> add x1 x2) <$> osc f1 <*> osc f2 )