[Haskell-beginners] Class instance for a type without a parameter
Daniel Fischer
daniel.is.fischer at googlemail.com
Sun Mar 11 17:10:56 CET 2012
On Sunday 11 March 2012, 16:57:30, Peter Hall wrote:
> Can someone remind me why I can't do this:
>
>
> data Digit = D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 | D8 | D9
> deriving (Eq, Ord, Show)
>
> instance Num [Digit] where ... -- This isn't allowed
>
It's because the language standard says that the types in the instance head
must be of the form
T a1 ... ak
with `T' a type constructor and the ai distinct type variables. Why that
is, I don't know.
You can make an
instance Num [Digit] where ...
if you enable
{-# LANGUAGE FlexibleInstances #-}
That's a harmless extension allowing instances of that form.
More information about the Beginners
mailing list