Почему я не могу сделать String экземпляром класса типов?

Given :

data Foo =
  FooString String
  …

class Fooable a where --(is this a good way to name this?)
  toFoo :: a -> Foo

Я хочу make 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 позволяет мне уйти от этого, если я добавлю дополнительный флаг. Это хорошая идея?
84
задан dave4420 9 May 2011 в 20:21
поделиться