Skip to content

Instantly share code, notes, and snippets.

@gfixler
Forked from merijn/MyState.hs
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfixler/d4bc7e688c12720a366b to your computer and use it in GitHub Desktop.
Save gfixler/d4bc7e688c12720a366b to your computer and use it in GitHub Desktop.
data MyState s a = MyState (s -> (a, s))
get :: MyState s s
get = undefined
put :: s -> MyState s ()
put = undefined
modify :: (s -> s) -> MyState s ()
modify = undefined
instance Functor (MyState s) where
-- fmap :: (a -> b) -> (MyState s) a -> (MyState s) b
fmap = undefined
instance Applicative (MyState s) where
-- pure :: a -> (MyState s) a
pure = undefined
-- (<*>) :: (MyState s) (a -> b) -> (MyState s) a -> (MyState s) b
(<*>) = undefined
instance Monad (MyState s) where
-- return :: a -> (MyState s) a
return = pure
-- (>>=) :: (MyState s) a -> (a -> (MyState s) b) -> (MyState s) b
(>>=) = undefined
data MyStateT s m a = MyStateT (s -> m (a, s))
get :: Monad m => MyStateT s m s
get = undefined
put :: Monad m => s -> MyStateT s m ()
put = undefined
modify :: Monad m => (s -> s) -> MyStateT s m ()
modify = undefined
instance Monad m => Functor (MyStateT s m) where
-- fmap :: (a -> b) -> (MyStateT s m) a -> (MyStateT s m) b
fmap = undefined
instance Monad m => Applicative (MyStateT s m) where
-- pure :: a -> (MyStateT s m) a
pure = undefined
-- (<*>) :: (MyStateT s m) (a -> b) -> (MyStateT s m) a -> (MyStateT s m) b
(<*>) = undefined
instance Monad m => Monad (MyStateT s m) where
-- return :: a -> (MyStateT s m) a
return = pure
-- (>>=) :: (MyStateT s m) a -> (a -> (MyStateT s m) b) -> (MyStateT s m) b
(>>=) = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment