mirror of
https://github.com/sdiehl/wiwinwlh.git
synced 2024-11-09 13:45:09 +03:00
simplify vm
This commit is contained in:
parent
d7bf030f0f
commit
88dbe3b44f
@ -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
|
||||
|
@ -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 ()
|
||||
|
Loading…
Reference in New Issue
Block a user