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.
Falende stack-operaties
Sign in to test your solution.
import Control.Applicative (Alternative(..))
import Control.Monad (liftM, ap, guard)
import Control.Monad.Fail (MonadFail(..))
import Control.Monad.Trans.Class (MonadTrans(lift))
-- State Monad
--------------
newtype State s a = State { runState :: s -> (a, s) }
instance Functor (State s) where
fmap = undefined
instance Applicative (State s) where
pure = undefined
(<*>) = undefined
instance Monad (State s) where
return a = State $ \s -> (a, s)
m >>= k = State $ \s -> let (x, s') = runState m s
in runState (k x) s'
get :: State s s
get = State $ \s -> (s, s)
put :: s -> State s ()
put s = State $ \_ -> ((), s)
modify :: (s -> s) -> State s ()
modify f = State $ \s -> ((), f s)
-- MaybeT MonadTransformer
---------------------------
newtype MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) }
instance Monad m => Functor (MaybeT m) where
fmap = undefined
{-
instantieer hier ook:
- Applicative
- Monad
- Alternative
- MonadFail
-}
instance MonadTrans MaybeT where
-- "herwrappen" van het argument
lift = undefined
-- Stack Manipulation
---------------------
type Stack = [Int]
-- plaats het argument bovenop de stack
push :: Int -> State Stack ()
push x = undefined
-- geef de grootte van de stack terug
size :: State Stack Int
size = undefined
-- neem het eerste element van de stack, als het aanwezig is
-- (hint: hoogle naar `guard`)
pop :: MaybeT (State Stack) Int
pop = undefined
-- haal de twee bovenste elementen van de stack, en plaats hun som er
-- terug op.
add :: MaybeT (State Stack) ()
add = undefined
mul :: MaybeT (State Stack) ()
mul = undefined
You can submit as many times as you like. Only your latest submission will be taken into account.
Sign in to test your solution.