__module__ Types __where__
__import__ __qualified__ Prelude
__import__ Prelude hiding ((>>=),return)
__import__ Data.Monoid
__class__ Monad1 m __where__
return1 :: a -> m a
bind1 :: m a -> (a -> m b) -> m b
__class__ Functor m => Monad2 m __where__
return :: a -> m a
join :: m (m a) -> m a
-- a)
bind2 :: Monad2 m => m a -> (a -> m b) -> m b
bind2 m f = join (fmap f m)
-- b)
join1 :: Monad1 m => m (m a) -> m a
join1 mm = bind1 mm id
-- c)
__instance__ Monad2 Maybe __where__
return = Just
join = joinMaybe
joinMaybe :: Maybe (Maybe a) -> Maybe a
joinMaybe (Just (Just x)) = Just x
joinMaybe _____ = Nothing
-- d)
__newtype__ State s a = State { runState :: s -> (a,s) }
__instance__ Functor (State s) __where__
fmap = fmapState
fmapState :: (a -> b) -> State s a -> State s b
fmapState f (State m) = State $ \ s -> __let__ (a, s') = m s
__in__ (f a, s')
__instance__ Monad2 (State s) __where__
return = returnState
join = joinState
returnState :: a -> State s a
returnState a = State $ \ s -> (a, s)
joinState :: State s (State s a) -> State s a
joinState (State mm) = State $ \ s ->
__let__ (m, s') = mm s
__in__ runState m s'
-- in runState m s -- planted bug