Haskell& Snap:每个请求状态的瞬态

时间:2016-10-21 07:24:36

标签: haskell haskell-snap-framework

如何在Snap中设置每个请求瞬态?

http://snapframework.com/docs/tutorials/snaplets-tutorial它说

  

Handler b v有一个MonadState v实例。这意味着您可以通过状态monad中可能熟悉的get,put,gets和modify函数来访问所有snaplet状态。

所以我正在尝试以下方法:

data App = App
    { _test :: Int
    }

然后在处理程序中:

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

然而我收到错误:

• 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;

任何想法如何实现?

谢谢!

0 个答案:

没有答案