Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a60ceff

Browse files
committed
rewrote things using Operational instead of MonadPrompt
1 parent d17fa91 commit a60ceff

File tree

4 files changed

+17
-44
lines changed

4 files changed

+17
-44
lines changed

‎aoc2017.cabal‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ library
2424
AOC2017.Util
2525
AOC2017.Util.Accum
2626
AOC2017.Util.Disjoints
27-
AOC2017.Util.Prompt
2827
AOC2017.Util.Tape
2928
other-modules: AOC2017.Day01
3029
AOC2017.Day02
@@ -52,8 +51,6 @@ library
5251
AOC2017.Day24
5352
AOC2017.Day25
5453
build-depends: base >= 4.7 && < 5
55-
, MonadPrompt
56-
, pointedlist
5754
, aeson
5855
, arithmoi
5956
, bytestring
@@ -71,6 +68,8 @@ library
7168
, monad-control
7269
, monad-loops
7370
, mtl
71+
, operational
72+
, pointedlist
7473
, reflection
7574
, split
7675
, text

‎src/AOC2017/Day18.hs‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Control.Applicative
1717
import Control.Lens
1818
import Control.Monad
1919
import Control.Monad.Fail
20-
import Control.Monad.Prompt (Prompt, prompt, runPromptM)
20+
import Control.Monad.Operational
2121
import Control.Monad.State (MonadState, StateT(..), State, execStateT, evalState)
2222
import Control.Monad.Trans.Maybe (MaybeT(..))
2323
import Control.Monad.Writer
@@ -78,20 +78,20 @@ data Command :: Type -> Type where
7878
CRcv :: Int -> Command Int -- ^ input is current value of buffer
7979
CSnd :: Int -> Command () -- ^ input is thing being sent
8080

81-
type Machine = Prompt (Memory :|: Command)
81+
type Machine = Program (Memory :|: Command)
8282

8383
cRcv :: Int -> Machine Int
84-
cRcv = prompt . R . CRcv
84+
cRcv = singleton . R . CRcv
8585
cSnd :: Int -> Machine ()
86-
cSnd = prompt . R . CSnd
86+
cSnd = singleton . R . CSnd
8787
cGet :: Char -> Machine Int
88-
cGet = prompt . L . MGet
88+
cGet = singleton . L . MGet
8989
cSet :: Char -> Int -> Machine ()
90-
cSet r = prompt . L . MSet r
90+
cSet r = singleton . L . MSet r
9191
cMov :: Int -> Machine ()
92-
cMov = prompt . L . MMov
92+
cMov = singleton . L . MMov
9393
cPk :: Machine Op
94-
cPk = prompt $ L MPk
94+
cPk = singleton $ L MPk
9595

9696
data ProgState = PS { _psTape :: P.PointedList Op
9797
, _psRegs :: M.Map Char Int
@@ -164,7 +164,7 @@ interpA = \case
164164

165165
day18a :: Challenge
166166
day18a = show
167-
. execPartA (many . runPromptM (interpMem >|< interpA) $ stepTape)
167+
. execPartA (many . interpretWithMonad (interpMem >|< interpA) $ stepTape)
168168
. (`PS` M.empty)
169169
. parse
170170

@@ -200,12 +200,12 @@ type MultiState = V.Vector 2 Thread
200200
stepThreads
201201
:: MaybeT (State MultiState) Int
202202
stepThreads = do
203-
outA <- execWriterT $
204-
zoom (V.ix 0) .many $ runPromptM (interpMem >|< interpB) stepTape
205-
outB <- execWriterT $
206-
zoom (V.ix 1) .many $ runPromptM (interpMem >|< interpB) stepTape
207-
V.ix 0 . tBuffer <>= outB
208-
V.ix 1 . tBuffer <>= outA
203+
outA <- execWriterT . zoom (V.ix 0) $
204+
many $ interpretWithMonad (interpMem >|< interpB) stepTape
205+
outB <- execWriterT . zoom (V.ix 1) $
206+
many $ interpretWithMonad (interpMem >|< interpB) stepTape
207+
V.ix 0 . tBuffer .= outB
208+
V.ix 1 . tBuffer .= outA
209209
guard . not $ null outA && null outB
210210
return $ length outB
211211

‎src/AOC2017/Util.hs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module AOC2017.Util (
88
) where
99

1010
import Data.List
11-
import Data.Traversable
1211
import qualified Data.Text as T
1312

1413
-- | Strict (!!)

‎src/AOC2017/Util/Prompt.hs‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /