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
RecursiveDo
is in theIO
monad. TheReactive
monad also has aMonadFix
instance. You can defineb
completely withinReactive
and then use async
around this to execute the entire definition as a transaction.The
RecursiveDo
notation 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
Behavior
from anEvent
is usually done withaccum
.In sodium this is a derived function and is internally defined in terms of
hold
,snapshot
, andmfix
.