TypeError constraint don't allow for instances

Sometimes, in haskell I want the following:

instance ('TypeError ('Text "This instance is bad")) => cls a where 
    meth = <What goes here> 

What exactly would I put here? I see 3 solutions. Use unsatisfieable instead of TypeError, or add a 0 param class that allows me to have access to (forall a. a), or just use undefined. I feel like I shouldn’t use Unsatisfiable, as what I am trying to do is report a type error, adding a 0 param class makes me worry the wrong error will be reported e.g. No instance for …, and undefined seems morally wrong. What exatcly is the recomended approach?

3 Likes

This is the intended use of Unsatisfiable actually! The docs even mention something equivalent to your example.

TypeError is mostly intended for use in type families. It can be a bit more unpredictable than Unsatisfiable when used in constraints.

3 Likes

Oh got it, I was confused because the names sounded like it was meant for a case where there was some precondition, and it needed to be checked, but did not fit. Can this get mentioned? Just adding that the TypeError will be rendered the exact same as the TypeError. (Or maybe it’s just me)