Warning! It seems that you are using Dodona within another webpage, so not everything may work properly. Let your teacher know so that he can solve the problem by adjusting a setting in the learning environment. In the meantime, you can click this link to open Dodona in a new window.
Warning! The page was not fully loaded, probably because of a network issue. It could be that not all functionalities work as expected. Please try reloading the page.
State Monad
Sign in to test your solution.
import Control.Monad (liftM, ap)
data State s a = State (s -> (a,s))
instance Monad (State s) where
return a = State $ \s -> (a,s)
m >>= k = State $ \s -> let (x,s') = run m s
in run (k x) s'
instance Functor (State s) where
-- ...
instance Applicative (State s) where
-- ...
-- Run the state transformer on given state, return the a value and the resulting state.
run :: State s a -> s -> (a, s)
run (State f) s = undefined
-- Get the state.
get :: State s s
get = undefined
-- Set the state.
put :: s -> State s ()
put s = undefined
-- Modify the state.
modify :: (s -> s) -> State s ()
modify f = undefined
-- Implement stack operations as state transformations.
type Stack = [Int]
push :: Int -> State Stack ()
push x = undefined
pop :: State Stack Int
pop = undefined
add, mult :: State Stack ()
add = undefined
mult = undefined