The BVar module
The basic building blocks for state are bvars and wires.

\begin{code}
module BVar (module BVar,Wire(..),newWire) where
import FranCore
\end{code}

A wire is an abstract data type containing an input listener and an event.
This uses newPrimRepeater from Event.hs, that generates a listener and
an event that communicate.

Comes from WirePrim.lhs

begin{code}
data Wire a = Wire {
	wireInput :: Listener a,
	wireEvent :: Event a
	}

newWire :: IO (Wire a)
newWire = do
 (l,e) <-  newPrimRepeater
 return $! Wire l e
end{code}

To represent basic state we use BVars. A value of type BVar a represents some
abstract mutable state of type a. A BVar is made from an event using accumE to
accumulate an event value based on a function valued event. We then use
stepper to turn the event into a behavior.

\begin{code}
data BVar a = BVar {
	bvarUpdInput :: Listener (a -> a),
	bvarEvent :: Event a,
	bvarBehavior :: Behavior a
	}

bvarInput :: BVar a -> Listener a
bvarInput (BVar {bvarUpdInput = upd}) = comapL const upd

newBVar :: a -> IO (BVar a)
newBVar a = do
 (Wire l e) <-  newWire
 e' <- a `accumE` e
 b <- a `stepper` e'
 return $! BVar l e' b

newBVarE :: a -> Event (a -> a) -> IO (BVar a)
newBVarE a inpE = do 
 (Wire l e) <-  newWire
 e' <- a `accumE` (e .|. inpE)
 b <- a `stepper` e'
 return $! BVar l e' b
\end{code}

To reduce the number of names in use, we have the Has_Event class. 
Wires and BVars are both members of this class.

\begin{code}

class Has_Event m where
 input :: m a -> Listener a
 event :: m a -> Event a

instance Has_Event Wire where
  input = wireInput
  event = wireEvent 

instance Has_Event BVar where
 input = bvarInput
 event = bvarEvent
\end{code}
