I’ve written some Haskell code which needs -XUndecidableInstances to compile. I do understand why that happens, that there is a certain condition which is violated and therefore GHC yells.
However, I’ve never come across a situation where the type checker would actually hang or wind up in an endless loop.
What does a non-terminating instance definition look like – can you give an example?
For example:
What is happening: When typing
f [x]the compiler needs to ensure thatx :: C [a]for somea. The instance declaration says thatxcan be of typeC [a]only if it is also of typeC [[a]]. So the compiler needs to ensure thatx :: C [[a]], etc. and gets caught in an infinite loop.See also Can using UndecidableInstances pragma locally have global consequences on compilation termination?