added lecture3

This commit is contained in:
Nicole Dresselhaus 2015-05-09 19:11:04 +02:00
parent bcff353228
commit f9ba19255e
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
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

BIN
lecture3.pdf Normal file

Binary file not shown.