Skip to content

Commit

Permalink
Merge pull request #276 from HeinrichApfelmus/delete-action-type
Browse files Browse the repository at this point in the history
refactor: delete Action newtype
  • Loading branch information
mitchellwrosen authored Nov 15, 2023
2 parents f13813b + e9fa8ac commit df59d01
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
2 changes: 1 addition & 1 deletion reactive-banana/reactive-banana.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Library
default-language: Haskell98
hs-source-dirs: src

build-depends: base >= 4.2 && < 5,
build-depends: base >= 4.10 && < 5,
deepseq >= 1.4.3.0 && < 1.5,
semigroups >= 0.13 && < 0.21,
containers >= 0.5 && < 0.7,
Expand Down
2 changes: 1 addition & 1 deletion reactive-banana/src/Reactive/Banana/Prim/Mid/Evaluation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ step (inputs,pulses)
$ runEvalP pulses
$ evaluatePulses inputs nGraphGC

doit latchUpdates -- update latch values from pulses
latchUpdates -- update latch values from pulses
applyDependencyChanges dependencyChanges -- rearrange graph topology
nGraphGC
GraphGC.removeGarbage nGraphGC -- remove unreachable pulses
Expand Down
6 changes: 3 additions & 3 deletions reactive-banana/src/Reactive/Banana/Prim/Mid/Plumbing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ addOutput p = do
runBuildIO :: BuildR -> BuildIO a -> IO (a, DependencyChanges, [Output])
runBuildIO i m = do
(a, BuildW (topologyUpdates, os, liftIOLaters, _)) <- unfold mempty m
doit liftIOLaters -- execute late IOs
liftIOLaters -- execute late IOs
return (a,topologyUpdates,os)
where
-- Recursively execute the buildLater calls.
Expand Down Expand Up @@ -196,7 +196,7 @@ changeParent pulse0 parent0 =
parent = _nodeP parent0

liftIOLater :: IO () -> Build ()
liftIOLater x = RW.tell $ BuildW (mempty, mempty, Action x, mempty)
liftIOLater x = RW.tell $ BuildW (mempty, mempty, x, mempty)

{-----------------------------------------------------------------------------
EvalL monad
Expand Down Expand Up @@ -245,7 +245,7 @@ readLatchFutureP :: Latch a -> EvalP (Future a)
readLatchFutureP = return . readLatchIO

rememberLatchUpdate :: IO () -> EvalP ()
rememberLatchUpdate x = RWS.tell ((Action x,mempty),mempty)
rememberLatchUpdate x = RWS.tell ((x,mempty),mempty)

rememberOutput :: (Output, EvalO) -> EvalP ()
rememberOutput x = RWS.tell ((mempty,[x]),mempty)
Expand Down
15 changes: 2 additions & 13 deletions reactive-banana/src/Reactive/Banana/Prim/Mid/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Build = ReaderWriterIOT BuildR BuildW IO
type BuildR = (Time, Pulse ())
-- ( current time
-- , pulse that always fires)
newtype BuildW = BuildW (DependencyChanges, [Output], Action, Maybe (Build ()))
newtype BuildW = BuildW (DependencyChanges, [Output], IO (), Maybe (Build ()))
-- reader : current timestamp
-- writer : ( actions that change the network topology
-- , outputs to be added to the network
Expand All @@ -69,17 +69,6 @@ data DependencyChange parent child
| ChangeParentTo child parent
type DependencyChanges = [DependencyChange SomeNode SomeNode]

{-----------------------------------------------------------------------------
Synonyms
------------------------------------------------------------------------------}
-- | 'IO' actions as a monoid with respect to sequencing.
newtype Action = Action { doit :: IO () }
instance Semigroup Action where
Action x <> Action y = Action (x >> y)
instance Monoid Action where
mempty = Action $ return ()
mappend = (<>)

{-----------------------------------------------------------------------------
Pulse and Latch
------------------------------------------------------------------------------}
Expand Down Expand Up @@ -134,7 +123,7 @@ mkWeakNodeValue x v = Ref.mkWeak x v Nothing

-- | Evaluation monads.
type EvalPW = (EvalLW, [(Output, EvalO)])
type EvalLW = Action
type EvalLW = IO ()

type EvalO = Future (IO ())
type Future = IO
Expand Down

0 comments on commit df59d01

Please sign in to comment.