[Haskell-cafe] Cons of -XUndecidableInstances

Yitzchak Gale gale at sefer.org
Tue Jun 7 17:20:16 CEST 2011

I 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.

wren ng thornton wrote:
>> 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))

I agree. I've even used that one (well, something similar

Oleg wrote:
> It seems that UndercidableInstances keep getting a bad rap.
> There are legitimate and decidable applications of
> UndercidableInstances. These applications have nothing to do
> with OOP, or HList for that matter... That extension should not
> be categorically stigmatized.

I'm sorry if I came across as giving it a bad rap, or
stigmatizing it. That was certainly not my intention. There
are plenty of excellent techniques that use this and other
GHC extensions; accomplished Haskellers should have
them in their toolbox.

But I stand by my statement, which is coming from my
perspective as a professional Haskell software developer,
not a PL researcher. Perhaps I should clarify it though.

I am making two claims:

1. In everyday practical Haskell programming, it is very
unusual that a technique requiring direct use of
UndecidableInstances is the right tool for the job. Of course,
that observation is colored by my own experience, but I
believe that it is generally true.

2. If a person is surprised by the GHC error suggesting
that UndecidableInstances is needed and is struggling with
understanding it, then it is almost certain that person has
inappropriately used OOP thinking in trying to design a
Haskell program.

Experienced Haskellers familiar with those techniques
do not get the error. Or they get it and say, "Oops, forgot
the UndecidableInstances."

Whereas most programmers coming to Haskell have had
OOP experience. The first thing that happens when they
try to write a program in Haskell of any significant complexity
is the "UndecidableInstances" error. It happened to me, too.


More information about the Haskell-Cafe mailing list