[Haskell-cafe] [ghc-proposals/cafe] Partially applied type families

Anthony Clayden anthony_clayden at clear.net.nz
Thu Jun 8 09:23:48 UTC 2017

> On Tue Jun 6 19:22:45 UTC 2017, Richard Eisenberg wrote:

> I still don't see why TypeError is problematic once we
> have instance guards.

Ah, "once we have instance guards", TypeError is never

With instance guards, you might sometimes want to put 
a TypeError instance, to give a more helpful message.
(HList nowadays exploits TypeError that way.)

OTOH, sometimes currently you want to say:
"I don't want to provide an instance for that pattern here,
 but by all means somebody else can elsewhere."

Example code to illustrate the above:

> module A
>   class C a b ...
>   instance C Int b ...
> module B
>   instance C a Bool ...

Those instances overlap irresolvably.
The only way you can catch (not really improve) is:

> instance (TypeError <help message>) => C Int Bool ...

But a) which module do you put that in?
b) what if somebody wants a `instance C Int Bool`?

with guards
> module A
>   class {-# INSTANCEGUARDS #-} C a b ...
>   instance C Int b | b /~ Bool ...
> module B
>   instance C a Bool | a /~ Int ...
> module C     -- if 'somebody else' wants
>   instance C Int Bool ...


More information about the Haskell-Cafe mailing list