Problems with instance list in Haskell

0

I have a job on the facu and I get this error:

  

'decide' is not a (visible) method of class 'Char'

for the code below:

data Paridade = Par | Impar deriving Show

class ParImpar a where
    decide :: a -> Paridade

instance ParImpar a => (Char [a]) where
    decide [a]
        | length [a] mod 2 == 0 = Par
        | otherwise = Impar
    
asked by anonymous 29.03.2017 / 20:45

1 answer

2

The problem is that you are trying to make an instance of Char (?!) to [a] . What you want is an instance of ParImpar to [a] :

instance ParImpar [a] where
    decide a
        | mod (length a) 2 == 0 = Par
        | otherwise             = Impar

Char is a type, not a typeclass.

    
20.04.2017 / 21:09