2014-04-21 54 views
0

在fpcomplete.com上,我正在閱讀使用yesod表單的教程:https://www.fpcomplete.com/school/advanced-haskell/building-a-file-hosting-service-in-yesod/part%202?show=tutorials。基於本教程中,我的主要功能是類型runSqlite和newTVar不匹配

main = do 
titems <- atomically $ newTVar [] 
liftIO $ warpEnv (Links titems) 

我想要做的就是啓動內存中的SQL數據庫,然後把從表格中的所有數據在內存中。但即使是很簡單的例子不工作:

main = runSqlite ":memory:" $ do 
-- runMigration migrateAll 
-- michaelId <- insert $ Person "Michael" $ Just 26 
-- michael <- get michaelId 
-- liftIO $ print michael 
titems <- atomically $ newTVar [] 
liftIO $ warpEnv (Links titems) 

我得到的錯誤是

src/[email protected]:13-39:36Couldn't match expected type `SqlPersistT 
           (Control.Monad.Logger.NoLoggingT 
            (Control.Monad.Trans.Resource.ResourceT m0)) 
           t0' 
      with actual type `IO (TVar [a0])' 
In a stmt of a 'do' block: titems <- atomically $ newTVar [] 
In the second argument of `($)', namely 
    `do { titems <- atomically $ newTVar []; 
     liftIO $ warpEnv (Links titems) }' 
In the expression: 
    runSqlite ":memory:" 
    $ do { titems <- atomically $ newTVar []; 
     liftIO $ warpEnv (Links titems) } 

我明白,莫名其妙的類型不匹配,但不知道我會爲了使用什麼功能要解決這個問題。如果有人能向我解釋發生了什麼,我將不勝感激。

回答

0

您需要在atomically前添加liftIO,才能將IO動作解除爲Persistent monad。