[Haskell-beginners] Class instance for a type without a parameter

Ozgur Akgun ozgurakgun at gmail.com
Sun Mar 11 17:09:17 CET 2012


Hi,

On 11 March 2012 15:57, Peter Hall <peter.hall at memorphic.com> 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
>

Why is it not allowed? Yes, it needs FlexibleInstances, but this is a
fairly common language extension so shouldn't be a big problem for most use
cases.

The error message generated by ghc should tell you about this. Following is
what I get for example:

Illegal instance declaration for `Num [Digit]'
      (All instance types must be of the form (T a1 ... an)
       where a1 ... an are *distinct type variables*,
       and each type variable appears at most once in the instance head.
       Use -XFlexibleInstances if you want to disable this.)
    In the instance declaration for `Num [Digit]'

HTH,
Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120311/391f36d1/attachment.htm>


More information about the Beginners mailing list