[Haskell-cafe] Cons of -XUndecidableInstances

wren ng thornton wren at freegeek.org
Tue Jun 7 07:49:13 CEST 2011

On 6/6/11 1:52 AM, Yitzchak Gale wrote:
> You almost never want to use UndecidableInstances
> when writing practical programs in Haskell.
> When GHC tells you that you need them, it almost
> always means that your types are poorly designed,
> usually due to influence from previous experience
> with OOP.

That's a bit unfair. There are many kinds of type-level hackery which 
require UndecidableInstances but are (a) perfectly safe for practical 
use, and (b) have nothing to do with OOP.

One particularly trivial example that comes to mind is:

     newtype Mu f = Mu (f (Mu f))

     instance Show (f (Mu f)) => Show (Mu f) where
         show (Mu x) = "Mu (" ++ show x ++ ")"
         -- Or however you'd like to show it

This can be solved for any f=F by,

     instance Show a => Show (F a) where...

Live well,

More information about the Haskell-Cafe mailing list