Skip to content

Apparent infinite loop producing error message with UndecidableSuperClasses

The code below causes the compiler to start printing out an error and then (apparently) loop indefinitely or run out of memory.

{-# LANGUAGE FlexibleContexts, FlexibleInstances, AllowAmbiguousTypes,
                         UndecidableSuperClasses #-}
module M where

data I = I

class All x => All x

class AllZip2 f
instance AllZip2 f

f1 :: (All x, AllZip2 I) => x -> ()
f1 = f2

f2 :: AllZip2 f => x -> ()
f2 _ = ()

I've looked at #11523, and while this seems similar I don't think it's quite the same as I don't see an infinite tower of superclasses, and I don't think it does ever give up and complain about too many iterations.

The error itself is probably genuine, as at the very least the type of f in the call to f2 is ambiguous, but it'd be nice to get it :-)

The output I get before the hang is something like this, I also checked GHC 8.6.4 and GHC 8.7.20190115:

GHCi, version 8.6.3: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling M             ( M.hs, interpreted )

M.hs:12:6: error:

The example is cut down from some real code that uses generics-sop, first by making a minimal example that still uses generics-sop and then by inlining and cutting down the library itself. I've also reported it on their tracker.

The seemingly nonsensical class All x => All x originates from this code in generics-sop where SListI xs = All Top xs is a superclass of All c xs.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information