5

I'm trying to define a Markdown newtype, and using GeneralizedNewtypeDeriving to automatically define new instances:

import Text.Markdown
import Yesod.Text.Markdown
import Database.Persist.Sql

newtype MarkdownNewT = MarkdownNewT { getMarkdown :: Markdown }
  deriving (Eq, IsString, Monoid, PersistField, PersistFieldSql)

This fails for the PersistFieldSql with the following message:

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’

Is this due to the new roles features of GHC 7.8.2? In that particular case I don't know what to do, since Markdown is itself a newtype over Text...

Or is this related with the forall on sqlType? What is the reason for this error when all other instances are successfully automatically derived?

Thanks

4

1 回答 1

6

Vector这看起来与GHC wiki Roles2页面中的一些示例(特别是一个)非常相似,这些示例不适用于当前角色系统,唉。

基本上问题是在

class PersistField a => PersistFieldSql a where
    sqlType :: Monad m => m a -> SqlType

monadm可以用其参数具有名义角色的类型构造函数来实例化,因此即使 和它们本身是,也不会以相同的方式表示m Markdown-并且m MarkdownNewT 当前角色系统无法限制禁止此类类型构造函数。MarkdownMarkdownNewTm

于 2014-09-17T14:58:50.960 回答