Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev handling state refactor #61

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions essence-of-live-coding/essence-of-live-coding.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,20 @@ library
, LiveCoding.Preliminary.LiveProgram.HotCodeSwap
, LiveCoding.Preliminary.LiveProgram.LiveProgram2
, LiveCoding.Preliminary.LiveProgram.LiveProgramPreliminary
, LiveCoding.HandlingState.AccumTOrphan

other-extensions: DeriveDataTypeable
build-depends:
base >= 4.11 && < 5
, transformers >= 0.5
, mtl >= 2.3
, containers >= 0.6
, syb >= 0.7
, vector-sized >= 1.2
, foreign-store >= 0.2
, time >= 1.9
, mmorph >= 1.1
, has-transformers
hs-source-dirs: src
default-language: Haskell2010
default-extensions: StrictData
Expand All @@ -105,6 +108,7 @@ test-suite test
, Feedback
, Handle
, Handle.LiveProgram
, HandlingState
, Monad
, Monad.Trans
, RuntimeIO.Launch
Expand All @@ -119,6 +123,7 @@ test-suite test
, transformers >= 0.5
, containers >= 0.6
, mtl >= 2.2
, mmorph >= 1.1
, essence-of-live-coding
, test-framework >= 0.8
, test-framework-quickcheck2 >= 0.3
Expand Down
17 changes: 17 additions & 0 deletions essence-of-live-coding/src/LiveCoding/Cell/Monad/Trans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ data State stateT stateInternal = State
}
deriving (Data, Eq, Show)

-- runAccumC
-- :: (Data accumT, Monad m)
-- => Cell (AccumT accumT m) a b
-- -- ^ A cell with an accum state effect
-- -> accumT
-- -- ^ The initial state
-- -> Cell m a (b, accumT)
-- -- ^ The cell, returning its current state
-- runAccumC cell stateT = _

-- | The internal state of a cell to which 'runAccumC' or 'runAccumL' has been applied.
data Accum accumT accumInternal = Accum
{ accumT :: accumT
, accumInternal :: accumInternal
}
deriving (Data, Eq, Show)

-- | Supply a 'ReaderT' environment before running the cell
runReaderC ::
r ->
Expand Down
9 changes: 9 additions & 0 deletions essence-of-live-coding/src/LiveCoding/Cell/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ edge = proc b -> do
bLast <- delay False -< b
returnA -< b && not bLast

changeInit :: (Monad m, Data a, Eq a) => a -> Cell m a (Maybe a)
changeInit a0 = proc a -> do
aLast <- delay a0 -< a
returnA -< guard (a /= aLast) >> Just a

change :: (Monad m, Data a, Eq a) => Cell m a (Maybe a)
change = arr Just >>> changeInit Nothing >>> arr join


-- * Debugging utilities

-- | Print the current UTC time, prepended with the first 8 characters of the given message.
Expand Down
Loading