我可能会做一些非常愚蠢的事情,但我想在同一个函数中将一些 Esqueleto 与常规持久查询混合。
我有功能:
handleFactionConstruction :: (BaseBackend backend ~ SqlBackend,
PersistStoreWrite backend, PersistQueryRead backend,
PersistUniqueRead backend, MonadIO m) =>
Time -> Entity Faction -> ReaderT backend m ()
handleFactionConstruction date faction = do
planets <- selectList [ PlanetOwnerId ==. Just (entityKey faction)] []
queues <- mapM loadPlanetConstructionQueue $ map entityKey planets
return ()
并且 loadPlanetConstructionQueue 具有签名(这个执行连接,因此我想在这里使用 Esqueleto):
loadPlanetConstructionQueue :: (MonadIO m, BackendCompatible SqlBackend backend,
PersistQueryRead backend, PersistUniqueRead backend) =>
Key Planet -> ReaderT backend m (Maybe (Entity Planet), [Entity BuildingConstruction
这不起作用,我收到以下错误:
Could not deduce (BackendCompatible SqlBackend backend)
arising from a use of ‘loadPlanetConstructionQueue’
from the context: (BaseBackend backend ~ SqlBackend,
PersistStoreWrite backend, PersistQueryRead backend,
PersistUniqueRead backend, MonadIO m)
bound by the type signature for:
handleFactionConstruction :: forall backend (m :: * -> *).
(BaseBackend backend ~ SqlBackend,
PersistStoreWrite backend,
PersistQueryRead backend,
PersistUniqueRead backend, MonadIO m) =>
Time -> Entity Faction -> ReaderT backend m ()
我认为这与“BackendCompatible SqlBackend backend”和“BaseBackend backend ~ SqlBackend”之间的区别有关。
有没有办法让这个工作?在这种情况下,我可以使用 Esqueleto 编写 selectList 部分,但更进一步,将需要使用替换,Esqueleto 不支持(我认为)。
我对 Haskell、Persistent 或 Esqueleto 了解不多,所以我在这里有点迷茫。