1
1
mirror of https://github.com/sdiehl/wiwinwlh.git synced 2024-11-09 13:45:09 +03:00

simplify vm

This commit is contained in:
Stephen Diehl 2014-04-06 03:28:07 -05:00
parent d7bf030f0f
commit 88dbe3b44f
3 changed files with 4 additions and 14 deletions

View File

@ -10,7 +10,7 @@ type Program = [Instr]
type VM a = ReaderT Program (WriterT Output (State Stack)) a
newtype Comp a = Comp { unComp :: ReaderT Program (WriterT Output (State Stack)) a }
newtype Comp a = Comp (VM a)
deriving (Monad, MonadReader Program, MonadWriter Output, MonadState Stack)
data Instr = Push Int | Pop | Puts
@ -20,11 +20,8 @@ evalInstr instr = case instr of
Pop -> modify tail
Push n -> modify (n:)
Puts -> do
val <- tos
tell [val]
tos :: VM Int
tos = gets head
tos <- gets head
tell [tos]
eval :: VM ()
eval = do

View File

@ -16,10 +16,4 @@ instance Monoid w => Monad (Writer w) where
tell :: w -> Writer w ()
tell w = Writer ((), w)
listen :: Writer w t -> Writer w (t, w)
listen m = Writer $ let (a, w) = runWriter m in ((a, w), w)
pass :: Writer t (a, t -> w) -> Writer w a
pass m = Writer $ let ((a, f), w) = runWriter m in (a, f w)
main = return ()

View File

@ -23,8 +23,7 @@ $(makeLenses ''Particle)
$(makeLenses ''Vector)
step :: StateT Box IO ()
step = do
zoom (particles.traverse) $ do
step = zoom (particles.traverse) $ do
dx <- use (vel.x)
dy <- use (vel.y)
pos.x += dx