鉴于:
data Foo =
FooString String
…
class Fooable a where --(is this a good way to name this?)
toFoo :: a -> Foo
我想创建String
一个实例Fooable
:
instance Fooable String where
toFoo = FooString
然后,GHC抱怨:
Illegal instance declaration for `Fooable String'
(All instance types must be of the form (T t1 ... tn)
where T is not a synonym.
Use -XTypeSynonymInstances if you want to disable this.)
In the instance declaration for `Fooable String'
如果相反,我使用[Char]
:
instance Fooable [Char] where
toFoo = FooString
GHC抱怨:
Illegal instance declaration for `Fooable [Char]'
(All instance types must be of the form (T a1 ... an)
where a1 ... an are type *variables*,
and each type variable appears at most once in the instance head.
Use -XFlexibleInstances if you want to disable this.)
In the instance declaration for `Fooable [Char]'
问题:
- 为什么我不能使String和类型类的实例?
- 如果我添加一个额外的标志,GHC似乎愿意让我解决这个问题。这是一个好主意吗?