Dato :
data Foo =
FooString String
…
class Fooable a where --(is this a good way to name this?)
toFoo :: a -> Foo
Voglio fare String
un'istanza di Fooable
:
instance Fooable String where
toFoo = FooString
GHC quindi si lamenta:
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'
Se invece utilizzo [Char]
:
instance Fooable [Char] where
toFoo = FooString
GHC si lamenta:
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]'
Domanda :
- Perché non posso creare String e istanza di una typeclass?
- GHC sembra disposto a lasciarmi andare via con questo se aggiungo una bandiera extra. E 'questa una buona idea?