on develop help sign in
Fix small laziness issue and add a test for it
commit61c1ffdbe7a014dfc01c2b2930d1212a1a79e794 authorRyan Trinkle <ryan.trinkle@gmail.com> dateThu 4 Aug 2016, 23:37 (10 years ago) parent8716849
2 files changed+12−3
src/Reflex/Spider/Internal.hs+1−1 test/Reflex/Test/Micro.hs+11−2
src/Reflex/Spider/Internal.hs+1−1
@@ -596,7 +596,7 @@ unsubscribe (EventSubscription msln _) = forM_ msln $ \sln -> WeakBag.remove sln
596596data Hold x p a
597597 = Hold { holdValue :: !(IORef a)
598598 , holdInvalidators :: !(IORef [Weak (Invalidator x)])
599− , holdEvent :: !(Event x (p a))
599+ , holdEvent :: Event x (p a) -- This must be lazy, or holds cannot be defined before their input Events
600600 , holdParent :: !(IORef (Maybe (EventSubscription x (p a)))) -- Keeps its parent alive (will be undefined until the hold is initialized) --TODO: Probably shouldn't be an IORef
601601#ifdef DEBUG_NODEIDS
602602 , holdNodeId :: Int
test/Reflex/Test/Micro.hs+11−2
@@ -1,9 +1,11 @@
1+{-# LANGUAGE BangPatterns #-}
12{-# LANGUAGE ConstraintKinds #-}
23{-# LANGUAGE FlexibleContexts #-}
34{-# LANGUAGE FlexibleInstances #-}
45{-# LANGUAGE GADTs #-}
56{-# LANGUAGE MultiParamTypeClasses #-}
67{-# LANGUAGE RankNTypes #-}
8+{-# LANGUAGE RecursiveDo #-}
79
810module Reflex.Test.Micro (testCases) where
911
@@ -12,12 +14,11 @@ import Reflex.TestPlan
1214
1315import Control.Applicative
1416import Control.Monad
17+import Control.Monad.Fix
1518import Data.Char
1619import Data.Functor.Misc
1720import Data.Monoid
18−
1921import Data.Foldable
20−
2122import qualified Data.Map as Map
2223
2324import Prelude
@@ -249,6 +250,14 @@ testCases =
249250 f <- fanMap . fmap toMap <$> events1
250251 return $ toList <$> mergeList [ select f (Const2 'b'), select f (Const2 'b'), select f (Const2 'e'), select f (Const2 'e') ]
251252
253+ , testE "lazy-hold" $ do
254+ let lazyHold :: forall t m. (Reflex t, MonadHold t m, MonadFix m) => m (Event t ())
255+ lazyHold = do
256+ rec !b <- hold never e
257+ let e = never <$ switch b
258+ return $ void e
259+ lazyHold
260+
252261 ] where
253262
254263 events1, events2, events3 :: TestPlan t m => m (Event t String)