为类型类函数键入签名,以允许在Yesod子网站中进行自定义SQL查询

时间:2014-04-17 16:39:36

标签: haskell yesod

目的是允许在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的类型签名以统一类型变量mastermaster0

0 个答案:

没有答案