[Haskell-beginners] FlexibleInstances

AntC anthony_clayden at clear.net.nz
Sun Nov 24 22:02:21 UTC 2013


> Emanuel Koczwara <poczta <at> emanuelkoczwara.pl> writes:

He Emanuel, you're doing well. 
Hardly anyone these days sticks to Haskell 98;
and really there's no need to.
(What you're trying to do can be achieved with H98,
 but would need some not-so-user-friendly coding.)

> 
>   I want to enable "instance [Char] where..." but disable "instance [a] 
where...". Is it possible?
> 

Yes, you're almost there.
You do need FlexibleInstances to be able to put [Char].

To ban [a], you need to ban overlapping instances.
{-# LANGUAGE NoOverlappingInstances #-}

(Usually overlapping instances is on by default.)

You're next error meesage is probably going to be,
    Illegal overlapping instance declaration for ...

Avoiding them is subtle, but a valuable discipline ;-)

HTH



More information about the Beginners mailing list