@@ -13,6 +13,7 @@ import Control.Monad.Fix
13import Data.Functor.Misc
13import Data.Functor.Misc
14import qualified Data.Map as M
14import qualified Data.Map as M
15import Data.These
15import Data.These
18import Reflex
19import Reflex
@@ -41,14 +42,48 @@ dynLoop (e1, e2) = do
41 return $ updated d'
42 return $ updated d'
45+connectButtonPromptly :: (MonadHold t m, Reflex t, MonadFix m) => Event t () -> Event t a -> m (Event t a)
46+connectButtonPromptly click e = do
47+ d <- holdDyn never (e <$ click)
50+connectButton :: (MonadHold t m, Reflex t, MonadFix m) => Event t () -> Event t a -> m (Event t a)
51+connectButton click e = do
52+ d <- hold never (e <$ click)
56+switchLoop :: (MonadHold t m, Reflex t, MonadFix m) => (Event t Int, Event t ()) -> m (Event t Int)
57+switchLoop (e1, e2) = do
59+ e' <- connectButton e2 (updated d)
60+ d <- count (align e' e1)
64+staticLoop :: AppWidget t m => m ()
67+ text "Typical error: GHC stack-space overflow: current limit is 33624 bytes"
68+ text "(or consumes all available memory)"
72+ d <- foldDyn (+) (0 :: Int) (leftmost [1 <$ e, updated d])
73+ dynText (T.pack . show <$> d)
44splitThese :: Filterable f => f (These a b) -> (f a, f b)
77splitThese :: Filterable f => f (These a b) -> (f a, f b)
45splitThese f = (mapMaybe (preview here) f, mapMaybe (preview there) f)
78splitThese f = (mapMaybe (preview here) f, mapMaybe (preview there) f)
47main :: IO ()
80main :: IO ()
48main = void $ do
81main = void $ do
83+ runApp' (switchLoop . splitThese) (Just <$> occs)
49 runApp' (dynLoop . splitThese) (Just <$> occs)
84 runApp' (dynLoop . splitThese) (Just <$> occs)
52− occs = [ This 1, This 2, That (), This 3 ]
87+ occs = [ This 1, This 2, That (), This 3 ]