user6307701
user6307701

Reputation:

Haskell & Snap: Transient per request state

How do I set per request transient-state in Snap?

Looking at http://snapframework.com/docs/tutorials/snaplets-tutorial it says

Handler b v has a MonadState v instance. This means that you can access all your snaplet state through the get, put, gets, and modify functions that are probably familiar from the state monad.

So I am trying the following:

data App = App
    { _test :: Int
    }

And then in the handler:

someHandler :: Handler App App ()
someHandler = do
    test <- gets _test
    liftIO $ print test
    put ( 2 :: Int _test

However I get the error:

• Couldn't match type ‘()’ with ‘Handler App App a0’
  Expected type: (App -> Int) -> Handler App App a0
    Actual type: (App -> Int) -> ()
• The function ‘put’ is applied to two arguments,
  its type is ‘s0 -> m0 ()’,
  it is specialized to ‘Int -> (App -> Int) -> ()’
  In a stmt of a 'do' block: put (2 :: Int) _test
  In the expression:
    do { test <- gets _test;
         liftIO $ print test;
         put (2 :: Int) _test;

Any ideas how to achieve that?

Thanks!

Upvotes: 1

Views: 101

Answers (0)

Related Questions