运行由另一个Monad包裹的Monad操作

时间:2016-10-24 19:40:20

标签: haskell yesod

鉴于websockets example如何在Handler内部runDB进行runDB $ selectList ...相关操作(例如chatStream :: WebSocketsT Handler () chatStream = do users <- liftIO $ runDB $ selectList [] [] :: Handler [Entity User] -- This line is not working sendTextData ("Welcome to the chat server, please enter your name." :: Text) -- ....

这是我想要做的一个非工作的例子:

Couldn't match type ‘HandlerT App IO [Entity User]’
               with ‘ReaderT
                       websockets-0.9.7.0:Network.WebSockets.Connection.Connection
                       Handler
                       t0’
Expected type: ReaderT
                 websockets-0.9.7.0:Network.WebSockets.Connection.Connection
                 Handler
                 t0
  Actual type: Handler [Entity User]
In a stmt of a 'do' block:
  users <- liftIO $ runDB $ selectList [] [] :: Handler [Entity User]

这是错误:

Error:(27, 13) Failed to resolve: com.google.android.gms:play-services:9.4.0
Install Repository and sync project
Show in File
Show in Project Structure dialog

1 个答案:

答案 0 :(得分:1)

答案是使用lift而非liftIO

users <- lift $ (runDB $ selectList [] [] :: Handler [Entity User])