Bawię się próbując zrozumieć zajęcia w Haskell. Napisałem głupie kilka linijek kodu, aby się zawiesić. Napisałem klasę o nazwie Slang
, która ma jedną funkcję. Kiedy robię Integer instancją mojej klasy, działa dobrze. Ale gdy ustawię String jako instancję mojej klasy, nie skompiluję. Ja już się wierciłem programem w oparciu o to, co mówi mi wynik błędu, ale bez skutku. Mam pojęcia, dlaczego to działa ...Nie można uczynić String instancją klasy w Haskell
Oto kod błędu następuje:
module Practice where
class Slang s where
slangify :: s -> String
instance Slang Integer where
slangify int = "yo"
instance Slang String where -- When I take this segment out, it works fine
slangify str = "bro"
BŁĄD:
Prelude> :load Practice
[1 of 1] Compiling Practice (Practice.hs, interpreted)
Practice.hs:9:10:
Illegal instance declaration for `Slang 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 `Slang String'
Failed, modules loaded: none.
Prelude>
Tak, masz rację !! Przepraszam, naprawiłem to – CodyBugstein