我運行到下面的編譯錯誤:持久的SelectList導致的錯誤 「無法匹配型 'BaseBackend backend0' 與 'SqlBackend'」
• Couldn't match type ‘BaseBackend backend0’ with ‘SqlBackend’
arising from a use of ‘runSqlite’
The type variable ‘backend0’ is ambiguous
• In the expression: runSqlite ":memory:"
In the expression:
runSqlite ":memory:"
$ do { records <- selectList [UserUsername ==. "abc"] [LimitTo 10];
liftIO $ print (records :: [Entity User]) }
In an equation for ‘selectAll’:
selectAll
= runSqlite ":memory:"
$ do { records <- selectList [UserUsername ==. "abc"] [LimitTo 10];
liftIO $ print (records :: [Entity User]) }
代碼:
selectAll :: IO()
selectAll = runSqlite ":memory:" $ do
records <- selectList [UserUsername ==. "abc"] [LimitTo 10]
liftIO $ print (records :: [Entity User])
有看看runSqlite的類型簽名:
runSqlite
:: (MonadBaseControl IO m, MonadIO m, IsSqlBackend backend)
=> Text
-> ReaderT backend (NoLoggingT (ResourceT m)) a
-> m a
我假設我需要指定runSq的顯式類型lite,儘管我不太確定我在ReaderT backend (NoLoggingT (ResourceT m)) a
中爲backend
設置了什麼?
這應該工作,你可以發佈整個代碼? – Sibi