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.
Haskell exercise
Error Monad
Sign in to hand in your solution and get feedback.
data Ofwel e a = Rechts a
| Links e
deriving (Show, Eq)
-- | Ofwel het exacte resultaat van een gehele deling, ofwel een foutboodschap.
safeDiv :: Int -> Int -> Ofwel String Int
safeDiv x y | y == 0 = Links "can't divide by zero"
| x `mod` y /= 0 = Links "not exact"
| otherwise = Rechts (x `div` y)
instance Functor (Ofwel e) where
fmap = undefined
instance Applicative (Ofwel e) where
pure = undefined
(<*>) = undefined
instance Monad (Ofwel e) where
return = undefined
(>>=) = undefined
-- | Kunnen we x appels en y peren eerlijk verdelen over z kinderen? Hoeveel vruchten krijgt elk?
sharing :: Int -> Int -> Int -> Ofwel String Int
sharing x y z = undefined
-- | Ofwel het n-de element van de lijst, ofwel een foutboodschap.
(!!?) :: [a] -> Int -> Ofwel String a
l !!? n = undefined