i would update a Behaviour (Cell / Val) from it's current value.
but the following code throws a thread blocked indefinitely in an MVar operation exception.
i have expected it prints three times 'value of i: '. what did i missing? - thanks.
{-# LANGUAGE RecursiveDo #-}
module Main where
import FRP.Sodium
main :: IO ()
main = do
(e, t) <- sync newEvent
rec
b <- sync $ hold 0 $ snapshot (\_ i -> i + 1) e b
sync $ listen (value b) (\i -> putStrLn $ "value of i: " ++ show i)
sync $ t "ping"
sync $ t "ping"
sync $ t "ping"
return ()
- GHCi, version 7.8.3
- sodium-0.11.0.3
Your recursive let from
RecursiveDois in theIOmonad. TheReactivemonad also has aMonadFixinstance. You can definebcompletely withinReactiveand then use asyncaround this to execute the entire definition as a transaction.The
RecursiveDonotation isn't helping with an example this simple. The same thing can be written more easily in terms ofmfix.It's probably worth mentioning that creating a
Behaviorfrom anEventis usually done withaccum.In sodium this is a derived function and is internally defined in terms of
hold,snapshot, andmfix.