Skip to content

Instantly share code, notes, and snippets.

@mightybyte
Created September 26, 2011 19:19
Show Gist options
  • Save mightybyte/1243114 to your computer and use it in GitHub Desktop.
Save mightybyte/1243114 to your computer and use it in GitHub Desktop.
MonadSnapletState
class Monad m => MonadSnapletState s m | m -> s where
getSnapletState :: m (Snaplet s)
putSnapletState :: (Snaplet s) -> m ()
modifySnapletState :: (MonadSnapletState s m) => (Snaplet s -> Snaplet s) -> m ()
modifySnapletState f = do
s <- getSnapletState
putSnapletState (f s)
getsSnapletState :: (MonadSnapletState s m) => (Snaplet s -> a) -> m a
getsSnapletState f = do
s <- getSnapletState
return (f s)
instance MonadSnapletState v (Handler b v) where
getSnapletState = Handler get
putSnapletState = Handler . put
instance MonadSnapletState v m => MonadState v m where
get = getsSnapletState _snapletValue
put v = do
s <- getSnapletState
modifySnapletState (setL snapletValue v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment