Skip to content
Snippets Groups Projects
Commit f9ba1925 authored by Nicole Dresselhaus's avatar Nicole Dresselhaus
Browse files

added lecture3

parent bcff3532
No related branches found
No related tags found
No related merge requests found
module MaybeIO where
import Control.Applicative
data MaybeIO a = MaybeIO { runMaybeIO :: IO (Maybe a) }
instance Functor MaybeIO where
fmap f = MaybeIO . fmap (fmap f) . runMaybeIO
instance Applicative MaybeIO where
pure = MaybeIO . pure . pure
f <*> x = MaybeIO $ (<*>) <$> f' <*> x'
where
f' = runMaybeIO f
x' = runMaybeIO x
instance Monad MaybeIO where
return = pure
x >>= f = MaybeIO $ x' >>= runMaybeIO . mb . fmap f
where
x' = runMaybeIO x
mb :: Maybe (MaybeIO a) -> MaybeIO a
mb (Just a) = a
mb Nothing = MaybeIO $ return Nothing
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment