我一起使用LevelDB庫和Snap框架。我有:Haskell:使捕捉和LevelDB發揮不錯
main :: IO()
main = runResourceT $ do
db <- open "thedb" defaultOptions { createIfMissing = True }
liftIO $ serveSnaplet defaultConfig $ initWeb db
現在,在我的處理程序,我不知道該如何才能查詢數據庫回到MonadResource IO
:
handleWords :: Handler App App()
handleWords = do
words <- uses thedb $ \db -> $ get db def "words"
writeBS $ pack $ show words
,給了我一個:No instance for (MonadResource IO) arising from a use of 'get'
任何想法?我覺得我錯過了一些關於如何正確創建monad「堆棧」的內容。謝謝
不,這是行不通的。因爲你已經退出'runResourceT'塊,'db'會立即關閉。您提出的代碼與'withFile「foo」ReadMode return'類似。 –
啊,對。我習慣於在其他情況下使用該模式,並忘記runResourceT強制清理。 – mightybyte