<pre style="white-space:pre-wrap;background-color:rgb(255,255,255)"><div dir="auto">> ... was mildly surprised by the need for -XUndecidableInstances</div><div dir="auto">> when deriving the 'Show' instance for the heterogenous N-ary product 'NP':</div><div dir="auto"><br></div><div dir="auto">Hi Viktor, yes 'Undecidable' sounds scary, but it isn't.</div><div dir="auto"><br></div><div dir="auto">There's been much debate: should we find a less scary name?</div><div dir="auto"><br></div><div dir="auto">Presumably your program compiles and runs OK with that switched on(?)</div><div dir="auto"><br></div><div dir="auto">Providing your program compiles, it is type-safe. The risk with -XUndecidableInstances is that you might throw the compiler into a loop, in which case you'll get a stack depth check, with an unhelpful error message.</div><div dir="auto"><br></div><div dir="auto">See the Users Guide on UndecidableInstances, also this is a faq on StackOverflow.
<br></div><div dir="auto">
>    deriving instance All (Compose Show f) xs => Show (NP f xs)</div><div dir="auto"><br></div><div dir="auto">Yes the constraint on that instance violates the Paterson Conditions</div><div dir="auto">(see Users Guide), the constraint is no smaller than the instance head.</div><div dir="auto">The P Conditions aim to make each step of instance resolution smaller,</div><div dir="auto">by strictly decreasing "constructors and variables (taken together ...".</div><div dir="auto">But that constraint has a count of 4, same as the head.


> I guess I should also ask whether there's a way to define something equivalent
> to 'Compose' without 'UndecidableSuperClasses', and perhaps the two are not unrelated.
<br></div><div dir="auto">Not exactly related, but again superclass instance resolution wants to make the problem smaller at each step. The definition for class Compose has a constraint no smaller than the class head (3 variables).</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">
> [ Perhaps I should be more blasé about enabling these extensions, but I prefer
>   to leave sanity checks enabled when possible. ]</div><div dir="auto"><br></div><div dir="auto">Yes that's a sensible policy. The trouble with -XUndecidableInstances is that it's a module-wide setting, so lifts the check for all instances of all classes.</div><div dir="auto">There are/were several proposals to make this a per-instance or per-class pragma.</div><div dir="auto">But they got no support in the proposals process.</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">AntC
<br></div></pre>