Monad transformers: Implementation of a stack machine with MaybeT (State Stack)
问题 I'm trying to implement a Maybe-State monad transformer and use it to implement a simple stack machine. The definitions of state monad and maybe should be correct. Now I'm trying to implement pop: pop :: MaybeT (State Stack) Int So that if the stack is empty it returns nothing, otherwise it returns Just <popped stack> . This is what I have so far: pop :: MaybeT (State Stack) Int pop = guard True (do (r:rs) <- get put rs return r) (Obviously True is just a dummy placeholder - I'll implement