目的是允许在Yesod子网站中进行自定义SQL查询,该查询可以在子网站处理程序中启动的同一个runDB事务中执行。
postSubSiteHandler :: forall master. (SubSiteInterface master, YesodAuthPersist master, KeyEntity (AuthId master) ~ User, YesodPersistBackend master ~ SqlPersistT)
lift $ runDB do
{- ... subsite-related queries ... -}
customQueries
如果我在子网站中包含customQueries
的定义,ghc会提供类型签名forall (m :: * -> *). (MonadResource m, MonadBaseControl IO m, MonadLogger m) => SqlPersistT m()
。
但是,customQueries
的定义应在SubSiteInstance
的实例中的子网站外提供。
尝试声明customQueries
:
class Yesod master => SubSiteInterface master where
customQueries :: forall (m :: * -> *).
(MonadResource m, MonadBaseControl IO m, MonadLogger m,
YesodPersistBackend master ~ SqlPersistT) =>
SqlPersistT m ()
上述声明不起作用。编译包含处理程序的模块时,它会给出以下错误消息:
Could not deduce (YesodPersistBackend master0 ~ SqlPersistT)
from the context (SubSiteInterface master,
KeyEntity (AuthId master) ~ User,
YesodPersistBackend master ~ SqlPersistT)
如何修改customQueries
的类型签名以统一类型变量master
和master0
?