Skip to content

Order of declarations affects which programs are accepted (type families and existentials)

Consider the following example:

{-# LANGUAGE ExistentialQuantification, TypeFamilies #-}
module Bug where

type family G n
type instance G a = F

data T = forall w. T (G w)
type family F where F = ()

-- type family G n

GHC rejects this program, when checking if T is ambiguous. However, if I move the declaration of G to the end of the file (the declaration that is commented out), then GHC accepts the program.

I would guess that, somehow, it matters in what order things are processed---if G is evaluated fully first, it can resolve to () and there is no ambiguity. However, if G is not evaluated, then there appears to be an ambiguity as w occurs under a type family.

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