Skip to content

Commit 52484eb

Browse files
committed
Delete buildDynamic, introduce liftPushM
1 parent cc419b3 commit 52484eb

9 files changed

Lines changed: 42 additions & 38 deletions

File tree

src/Reflex/Class.hs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ module Reflex.Class
156156
-- * Deprecated functions
157157
, switchPromptly
158158
, switchPromptOnly
159+
, buildDynamic
159160
-- * "Cheap" functions
160161
, fmapMaybeCheap
161162
, mapMaybeCheap
@@ -388,6 +389,9 @@ instance (Reflex t, Default a) => Default (Dynamic t a) where
388389
class (Applicative m, Monad m) => MonadSample t m | m -> t where
389390
-- | Get the current value in the 'Behavior'
390391
sample :: Behavior t a -> m a
392+
{-# INLINABLE sample #-}
393+
default sample :: (m ~ f m', MonadTrans f, MonadSample t m') => Behavior t a -> m a
394+
sample = lift . sample
391395

392396
-- | 'MonadHold' designates monads that can create new 'Behavior's based on
393397
-- 'Event's; usually this will be 'PushM' or a monad based on it. 'MonadHold'
@@ -400,33 +404,39 @@ class MonadSample t m => MonadHold t m where
400404
-- the 'Behavior', it will see the __old__ value of the 'Behavior', not the new
401405
-- one.
402406
hold :: a -> Event t a -> m (Behavior t a)
407+
{-# INLINABLE hold #-}
403408
default hold :: (m ~ f m', MonadTrans f, MonadHold t m') => a -> Event t a -> m (Behavior t a)
404409
hold v0 = lift . hold v0
405410
-- | Create a 'Dynamic' value using the given initial value that changes every
406411
-- time the 'Event' occurs.
407412
holdDyn :: a -> Event t a -> m (Dynamic t a)
413+
{-# INLINABLE holdDyn #-}
408414
default holdDyn :: (m ~ f m', MonadTrans f, MonadHold t m') => a -> Event t a -> m (Dynamic t a)
409415
holdDyn v0 = lift . holdDyn v0
410416
-- | Create an 'Incremental' value using the given initial value that changes
411417
-- every time the 'Event' occurs.
412418
holdIncremental :: Patch p => PatchTarget p -> Event t p -> m (Incremental t p)
419+
{-# INLINABLE holdIncremental #-}
413420
default holdIncremental :: (Patch p, m ~ f m', MonadTrans f, MonadHold t m') => PatchTarget p -> Event t p -> m (Incremental t p)
414421
holdIncremental v0 = lift . holdIncremental v0
415-
buildDynamic :: PushM t a -> Event t a -> m (Dynamic t a)
416-
{-
417-
default buildDynamic :: (m ~ f m', MonadTrans f, MonadHold t m') => PullM t a -> Event t a -> m (Dynamic t a)
418-
buildDynamic getV0 = lift . buildDynamic getV0
419-
-}
420422
-- | Create a new 'Event' that only occurs only once, on the first occurrence of
421423
-- the supplied 'Event'.
422424
headE :: Event t a -> m (Event t a)
425+
{-# INLINABLE headE #-}
426+
default headE :: (m ~ f m', MonadTrans f, MonadHold t m') => Event t a -> m (Event t a)
427+
headE = lift . headE
423428
-- | An event which only occurs at the current moment in time, such that:
424429
--
425430
-- > coincidence (pushAlways (\a -> (a <$) <$> now) e) = e
426431
--
427432
now :: m (Event t ())
433+
{-# INLINABLE now #-}
428434
default now :: (m ~ f m', MonadTrans f, MonadHold t m') => m (Event t ())
429435
now = lift now
436+
{-# INLINABLE liftPushM #-}
437+
liftPushM :: PushM t a -> m a
438+
default liftPushM :: (m ~ f m', MonadTrans f, MonadHold t m') => PushM t a -> m a
439+
liftPushM = lift . liftPushM
430440

431441
-- | Accumulate an 'Incremental' with the supplied initial value and the firings of the provided 'Event',
432442
-- using the combining function to produce a patch.
@@ -570,7 +580,6 @@ instance MonadHold t m => MonadHold t (ReaderT r m) where
570580
hold a0 = lift . hold a0
571581
holdDyn a0 = lift . holdDyn a0
572582
holdIncremental a0 = lift . holdIncremental a0
573-
buildDynamic a0 = lift . buildDynamic a0
574583
headE = lift . headE
575584
now = lift now
576585

@@ -581,7 +590,6 @@ instance (MonadHold t m, Monoid r) => MonadHold t (WriterT r m) where
581590
hold a0 = lift . hold a0
582591
holdDyn a0 = lift . holdDyn a0
583592
holdIncremental a0 = lift . holdIncremental a0
584-
buildDynamic a0 = lift . buildDynamic a0
585593
headE = lift . headE
586594
now = lift now
587595

@@ -592,7 +600,6 @@ instance MonadHold t m => MonadHold t (StateT s m) where
592600
hold a0 = lift . hold a0
593601
holdDyn a0 = lift . holdDyn a0
594602
holdIncremental a0 = lift . holdIncremental a0
595-
buildDynamic a0 = lift . buildDynamic a0
596603
headE = lift . headE
597604
now = lift now
598605

@@ -603,7 +610,6 @@ instance MonadHold t m => MonadHold t (ExceptT e m) where
603610
hold a0 = lift . hold a0
604611
holdDyn a0 = lift . holdDyn a0
605612
holdIncremental a0 = lift . holdIncremental a0
606-
buildDynamic a0 = lift . buildDynamic a0
607613
headE = lift . headE
608614
now = lift now
609615

@@ -614,7 +620,6 @@ instance (MonadHold t m, Monoid w) => MonadHold t (RWST r w s m) where
614620
hold a0 = lift . hold a0
615621
holdDyn a0 = lift . holdDyn a0
616622
holdIncremental a0 = lift . holdIncremental a0
617-
buildDynamic a0 = lift . buildDynamic a0
618623
headE = lift . headE
619624
now = lift now
620625

@@ -625,7 +630,6 @@ instance MonadHold t m => MonadHold t (ContT r m) where
625630
hold a0 = lift . hold a0
626631
holdDyn a0 = lift . holdDyn a0
627632
holdIncremental a0 = lift . holdIncremental a0
628-
buildDynamic a0 = lift . buildDynamic a0
629633
headE = lift . headE
630634
now = lift now
631635

@@ -1693,3 +1697,9 @@ switchPromptly = switchHoldPromptly
16931697
-- | See 'switchHoldPromptOnly'
16941698
switchPromptOnly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
16951699
switchPromptOnly = switchHoldPromptOnly
1700+
1701+
{-# DEPRECATED buildDynamic "Sample directly and use 'liftPushM'" #-}
1702+
buildDynamic :: (MonadHold t m) => PushM t a -> Event t a -> m (Dynamic t a)
1703+
buildDynamic initialValue e = do
1704+
iv <- liftPushM initialValue
1705+
holdDyn iv e

src/Reflex/EventWriter/Base.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ instance MonadHold t m => MonadHold t (EventWriterT t w m) where
141141
holdDyn v0 = lift . holdDyn v0
142142
{-# INLINABLE holdIncremental #-}
143143
holdIncremental v0 = lift . holdIncremental v0
144-
{-# INLINABLE buildDynamic #-}
145-
buildDynamic a0 = lift . buildDynamic a0
146144
{-# INLINABLE headE #-}
147145
headE = lift . headE
148146
{-# INLINABLE now #-}
149147
now = lift now
148+
{-# INLINABLE liftPushM #-}
149+
liftPushM = lift . liftPushM
150150

151151
instance (Reflex t, Adjustable t m, MonadHold t m, Semigroup w) => Adjustable t (EventWriterT t w m) where
152152
runWithReplace = runWithReplaceEventWriterTWith $ \dm0 dm' -> lift $ runWithReplace dm0 dm'

src/Reflex/PerformEvent/Base.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ instance (ReflexHost t, MonadHold t m) => MonadHold t (PerformEventT t m) where
164164
holdDyn v0 v' = PerformEventT $ lift $ holdDyn v0 v'
165165
{-# INLINABLE holdIncremental #-}
166166
holdIncremental v0 v' = PerformEventT $ lift $ holdIncremental v0 v'
167-
{-# INLINABLE buildDynamic #-}
168-
buildDynamic getV0 v' = PerformEventT $ lift $ buildDynamic getV0 v'
169167
{-# INLINABLE headE #-}
170168
headE = PerformEventT . lift . headE
171169
{-# INLINABLE now #-}
172170
now = PerformEventT . lift $ now
171+
{-# INLINABLE liftPushM #-}
172+
liftPushM = PerformEventT . lift . liftPushM
173173

174174
instance (MonadRef (HostFrame t), ReflexHost t) => MonadRef (PerformEventT t m) where
175175
type Ref (PerformEventT t m) = Ref (HostFrame t)

src/Reflex/PostBuild/Base.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ instance MonadHold t m => MonadHold t (PostBuildT t m) where
9494
holdDyn v0 = lift . holdDyn v0
9595
{-# INLINABLE holdIncremental #-}
9696
holdIncremental v0 = lift . holdIncremental v0
97-
{-# INLINABLE buildDynamic #-}
98-
buildDynamic a0 = lift . buildDynamic a0
9997
{-# INLINABLE headE #-}
10098
headE = lift . headE
10199
{-# INLINABLE now #-}
102100
now = lift now
101+
{-# INLINABLE liftPushM #-}
102+
liftPushM = lift . liftPushM
103103

104104
instance PerformEvent t m => PerformEvent t (PostBuildT t m) where
105105
type Performable (PostBuildT t m) = Performable m

src/Reflex/Profiled.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ instance MonadHold t m => MonadHold (ProfiledTimeline t) (ProfiledM m) where
188188
hold v0 (Event_Profiled v') = ProfiledM $ Behavior_Profiled <$> hold v0 v'
189189
holdDyn v0 (Event_Profiled v') = ProfiledM $ Dynamic_Profiled <$> holdDyn v0 v'
190190
holdIncremental v0 (Event_Profiled v') = ProfiledM $ Incremental_Profiled <$> holdIncremental v0 v'
191-
buildDynamic (ProfiledM v0) (Event_Profiled v') = ProfiledM $ Dynamic_Profiled <$> buildDynamic v0 v'
192191
headE (Event_Profiled e) = ProfiledM $ Event_Profiled <$> headE e
193192
now = ProfiledM $ Event_Profiled <$> now
193+
liftPushM (ProfiledM m) = ProfiledM . liftPushM $ m
194194

195195
instance MonadSample t m => MonadSample (ProfiledTimeline t) (ProfiledM m) where
196196
sample (Behavior_Profiled b) = ProfiledM $ sample b

src/Reflex/Pure.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,6 @@ instance (Enum t, HasTrie t, Ord t) => MonadHold (Pure t) ((->) t) where
190190
b <- hold v0 e
191191
pure $ unsafeDynamic b e
192192

193-
buildDynamic :: (t -> a) -> Event (Pure t) a -> t -> Dynamic (Pure t) a
194-
buildDynamic initialValue e = do
195-
iv <- initialValue
196-
holdDyn iv e
197-
198193
holdIncremental :: Patch p => PatchTarget p -> Event (Pure t) p -> t -> Incremental (Pure t) p
199194
holdIncremental initialValue e initialTime = Incremental $ \t -> (f t, unEvent e t)
200195
where f = memo $ \sampleTime ->
@@ -211,3 +206,4 @@ instance (Enum t, HasTrie t, Ord t) => MonadHold (Pure t) ((->) t) where
211206

212207
headE = slowHeadE
213208
now t = Event $ guard . (t ==)
209+
liftPushM = id

src/Reflex/Spider/Internal.hs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,15 +2514,13 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Event
25142514
holdDyn = holdDynSpiderEventM
25152515
{-# INLINABLE holdIncremental #-}
25162516
holdIncremental = holdIncrementalSpiderEventM
2517-
{-# INLINABLE buildDynamic #-}
2518-
buildDynamic (SpiderPushM getV0) e = do
2519-
v0 <- getV0
2520-
R.holdDyn v0 e
25212517
{-# INLINABLE headE #-}
25222518
headE = R.slowHeadE
25232519
-- headE (SpiderEvent e) = SpiderEvent <$> Reflex.Spider.Internal.headE e
25242520
{-# INLINABLE now #-}
25252521
now = nowSpiderEventM
2522+
{-# INLINABLE liftPushM #-}
2523+
liftPushM (SpiderPushM m) = m
25262524

25272525
instance Reflex.Class.MonadSample (SpiderTimeline x) (SpiderPullM x) where
25282526
{-# INLINABLE sample #-}
@@ -2539,13 +2537,13 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide
25392537
holdDyn v0 (SpiderEvent e) = SpiderPushM $ fmap (SpiderDynamic . dynamicHoldIdentity) $ Reflex.Spider.Internal.hold v0 $ coerce e
25402538
{-# INLINABLE holdIncremental #-}
25412539
holdIncremental v0 (SpiderEvent e) = SpiderPushM $ SpiderIncremental . dynamicHold <$> Reflex.Spider.Internal.hold v0 e
2542-
{-# INLINABLE buildDynamic #-}
2543-
buildDynamic getV0 e = SpiderPushM $ Reflex.Class.buildDynamic getV0 e
25442540
{-# INLINABLE headE #-}
25452541
headE = R.slowHeadE
25462542
-- headE (SpiderEvent e) = SpiderPushM $ SpiderEvent <$> Reflex.Spider.Internal.headE e
25472543
{-# INLINABLE now #-}
25482544
now = SpiderPushM nowSpiderEventM
2545+
{-# INLINABLE liftPushM #-}
2546+
liftPushM = id
25492547

25502548

25512549
instance HasSpiderTimeline x => Monad (Reflex.Class.Dynamic (SpiderTimeline x)) where
@@ -2597,12 +2595,12 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide
25972595
holdDyn v0 e = runFrame . runSpiderHostFrame $ Reflex.Class.holdDyn v0 e
25982596
{-# INLINABLE holdIncremental #-}
25992597
holdIncremental v0 e = runFrame . runSpiderHostFrame $ Reflex.Class.holdIncremental v0 e
2600-
{-# INLINABLE buildDynamic #-}
2601-
buildDynamic getV0 e = runFrame . runSpiderHostFrame $ Reflex.Class.buildDynamic getV0 e
26022598
{-# INLINABLE headE #-}
26032599
headE e = runFrame . runSpiderHostFrame $ Reflex.Class.headE e
26042600
{-# INLINABLE now #-}
26052601
now = runFrame . runSpiderHostFrame $ Reflex.Class.now
2602+
{-# INLINABLE liftPushM #-}
2603+
liftPushM = runFrame . runSpiderHostFrame . Reflex.Class.liftPushM
26062604

26072605

26082606
instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHostFrame x) where
@@ -2615,13 +2613,13 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide
26152613
holdDyn v0 e = SpiderHostFrame $ fmap (SpiderDynamic . dynamicHoldIdentity) $ Reflex.Spider.Internal.hold v0 $ coerce $ unSpiderEvent e
26162614
{-# INLINABLE holdIncremental #-}
26172615
holdIncremental v0 e = SpiderHostFrame $ fmap (SpiderIncremental . dynamicHold) $ Reflex.Spider.Internal.hold v0 $ unSpiderEvent e
2618-
{-# INLINABLE buildDynamic #-}
2619-
buildDynamic getV0 e = SpiderHostFrame $ Reflex.Class.buildDynamic getV0 e
26202616
{-# INLINABLE headE #-}
26212617
headE = R.slowHeadE
26222618
-- headE (SpiderEvent e) = SpiderHostFrame $ SpiderEvent <$> Reflex.Spider.Internal.headE e
26232619
{-# INLINABLE now #-}
26242620
now = SpiderHostFrame Reflex.Class.now
2621+
{-# INLINABLE liftPushM #-}
2622+
liftPushM = SpiderHostFrame . Reflex.Class.liftPushM
26252623

26262624
instance HasSpiderTimeline x => Reflex.Class.MonadSample (SpiderTimeline x) (SpiderHost x) where
26272625
{-# INLINABLE sample #-}
@@ -2638,12 +2636,12 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Refle
26382636
holdDyn v0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.holdDyn v0 e
26392637
{-# INLINABLE holdIncremental #-}
26402638
holdIncremental v0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.holdIncremental v0 e
2641-
{-# INLINABLE buildDynamic #-}
2642-
buildDynamic getV0 e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.buildDynamic getV0 e
26432639
{-# INLINABLE headE #-}
26442640
headE e = Reflex.Spider.Internal.ReadPhase $ Reflex.Class.headE e
26452641
{-# INLINABLE now #-}
26462642
now = Reflex.Spider.Internal.ReadPhase Reflex.Class.now
2643+
{-# INLINABLE liftPushM #-}
2644+
liftPushM = Reflex.Spider.Internal.ReadPhase . Reflex.Class.liftPushM
26472645

26482646
--------------------------------------------------------------------------------
26492647
-- Deprecated items

src/Reflex/TriggerEvent/Base.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ instance MonadHold t m => MonadHold t (TriggerEventT t m) where
127127
holdDyn v0 v' = lift $ holdDyn v0 v'
128128
{-# INLINABLE holdIncremental #-}
129129
holdIncremental v0 v' = lift $ holdIncremental v0 v'
130-
{-# INLINABLE buildDynamic #-}
131-
buildDynamic a0 = lift . buildDynamic a0
132130
{-# INLINABLE headE #-}
133131
headE = lift . headE
134132
{-# INLINABLE now #-}
135133
now = lift now
134+
{-# INLINABLE liftPushM #-}
135+
liftPushM = lift . liftPushM
136136

137137
instance Adjustable t m => Adjustable t (TriggerEventT t m) where
138138
{-# INLINABLE runWithReplace #-}

test/Reflex/Plan/Pure.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ instance MonadHold (Pure Int) PurePlan where
3939
hold initial = liftPlan . hold initial
4040
holdDyn initial = liftPlan . holdDyn initial
4141
holdIncremental initial = liftPlan . holdIncremental initial
42-
buildDynamic getInitial = liftPlan . buildDynamic getInitial
4342
headE = liftPlan . headE
4443
now = liftPlan now
44+
liftPushM = liftPlan . liftPushM
4545

4646
instance MonadSample (Pure Int) PurePlan where
4747
sample = liftPlan . sample

0 commit comments

Comments
 (0)