Purescript-express 中处理程序内的 StateT monad

问题描述 投票:0回答:0

我想在 StateT monad 中保存一些数据,

Handler
(任何http方法)函数的
post
内我想修改存储在状态中的数据......但问题是我不能在Handler中使用State......

newtype HandlerM a =  HandlerM (Request -> Response -> Effect Unit -> Aff a)

type Handler = HandlerM Unit

和类型的http方法如下,

post :: forall r. RoutePattern r => r -> Handler -> App

我想做类似的事情,

post "/some/api" $ do 
     S.modify (\s -> s { count = s.+ 1}} ---- modify state with respect to response 
     --- handle request

ps:我可以使用

ref
但是有什么方法可以在 Handler 中使用 StateT ...

functional-programming purescript
© www.soinside.com 2019 - 2024. All rights reserved.