Skip to content

Instantly share code, notes, and snippets.

@bluescreen303
Created April 10, 2012 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluescreen303/2350944 to your computer and use it in GitHub Desktop.
Save bluescreen303/2350944 to your computer and use it in GitHub Desktop.
diff --git a/reactive-banana/src/Reactive/Banana/Internal/CompileModel.hs b/reactive-banana/src/Reactive/Banana/Internal/CompileModel.hs
index a9b78df..c3e07e8 100644
--- a/reactive-banana/src/Reactive/Banana/Internal/CompileModel.hs
+++ b/reactive-banana/src/Reactive/Banana/Internal/CompileModel.hs
@@ -27,12 +27,15 @@ import Reactive.Banana.Model
data InputToEvent = InputToEvent (forall a. InputChannel a -> Event a)
type Compile a b = (InputToEvent -> IO (Event a,b)) -> IO (Automaton a,b)
+
+data Box a = Box { unBox :: a }
+
compileWithGlobalInput :: Compile a b
compileWithGlobalInput f = do
-- reference that holds input values
- (ref :: IORef [InputValue]) <- newIORef undefined
+ (ref :: IORef (Box [InputValue])) <- newIORef (Box undefined)
-- An infinite list of all future input values. Very unsafe!
- (inputs :: Event [InputValue]) <- unsafeSequence (Just <$> readIORef ref)
+ (inputs :: Event [InputValue]) <- unsafeSequence (Just . unBox <$> readIORef ref)
let
inputToEvent = InputToEvent $
@@ -46,7 +49,7 @@ compileWithGlobalInput f = do
-- step of the automaton
step values outputs = do
- writeIORef ref values -- write new input value
+ writeIORef ref (Box values) -- write new input value
(o:outputs) <- evaluate outputs -- make sure that output is in WHNF
return (o, outputs) -- return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment