我正在尝试定义Markdown newtype,并使用GeneralizedNewtypeDeriving
自动定义新实例:
import Text.Markdown import Yesod.Text.Markdown import Database.Persist.Sql newtype MarkdownNewT = MarkdownNewT { getMarkdown :: Markdown } deriving (Eq, IsString, Monoid, PersistField, PersistFieldSql)
对于PersistFieldSql
以下消息,此操作失败:
Could not coerce from ‘m Markdown’ to ‘m MarkdownNewT’ because ‘m Markdown’ and ‘m MarkdownNewT’ are different types. arising from the coercion of the method ‘sqlType’ from type ‘forall (m :: * -> *). Monad m => m Markdown -> SqlType’ to type ‘forall (m :: * -> *). Monad m => m MarkdownNewT -> SqlType’
这是由于GHC 7.8.2 的新角色功能吗?在那种特殊情况下,我不知道该怎么做,因为Markdown本身就是Text的新类型......
或者这与forall
on有关sqlType
?当所有其他实例成功自动派生时,出现此错误的原因是什么?
谢谢
这看起来非常类似于Vector
GHC wiki Roles2页面中与当前角色系统不兼容的一些示例(特别是一个),唉.
基本上问题在于
class PersistField a => PersistFieldSql a where sqlType :: Monad m => m a -> SqlType
单子m
可能与类型构造,其说法有标称的作用被实例化,从而使m Markdown
与m MarkdownNewT
不相同的代表,即使Markdown
和MarkdownNewT
自己的-和当前角色系统没有限制的方式m
来禁止这种类型的构造函数.