我可能做了一些非常愚蠢的事情,但我想将一些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后端“和"BaseBackend后端~ SqlBackend”之间的区别有关。
有什么办法能让我做到这一点吗?在这种情况下,我可以用Esqueleto编写selectList部分,但是在更长的一段时间内需要使用replace,这是Esqueleto不支持的(我认为)。
我对Haskell,Persistent或Esqueleto不太了解,所以我有点迷失在这里。
发布于 2018-10-05 13:37:49
可以将BackendCompatible SqlBackend backend添加到handleFactionConstruction的约束列表中,以获得:
handleFactionConstruction :: (BaseBackend backend ~ SqlBackend,
BackendCompatible SqlBackend backend
PersistStoreWrite backend, PersistQueryRead backend,
PersistUniqueRead backend, MonadIO m) =>
Time -> Entity Faction -> ReaderT backend m ()更普遍地说,Could not deduce错误意味着您的类型签名比它允许的一个函数更通用。处理这一问题的方法有三种:
loadPlanetConstructionQueue)更通用https://stackoverflow.com/questions/52657920
复制相似问题