Problems with instance list in Haskell

Asked

Viewed 64 times

0

I have a job at the facu and I have this mistake:

'decide' is not a (Visible) method of class `Char'

to 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

1 answer

2

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

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

Char is a type, not a typeclass.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.