Sto cercando di capire le classi in Haskell. Ho scritto poche sciocche code di codice per farcela. Ho scritto una classe chiamata Slang
che ha una funzione. Quando trasformo Integer in un'istanza della mia classe, funziona perfettamente. Ma quando creo String un'istanza della mia classe non verrà compilata. Sono stato irrequieto con il programma in base a ciò che l'output dell'errore mi dice, ma senza risultato. Ho idea del perché funziona ...Impossibile rendere a String un'istanza di una classe in Haskell
ecco il codice seguito da l'errore:
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"
ERRORE:
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>
Sì hai ragione !! Scusa, l'ho risolto – CodyBugstein