Perhaps this is obvious, but Forall's skolemization is not typesafe in the pressence of incoherent instances. Basically, you can define
class OneOf a b c where
oneOf :: Either (a :==: c) (b :==: c)
instance OneOf a b a where
oneOf = Left Refl
instance OneOf a b b where
oneOf = Right Refl
oneOfaba :: Dict (OneOf a b a)
oneOfaba = Dict
oneOfabb :: Dict (OneOf a b b)
oneOfabb = Dict
oneOfEither :: k :- (OneOf a b a,OneOf a b b)
oneOfEither = (Sub oneOfaba) &&& (Sub oneOfabb)
this really quickly becomes a problem
data Oh k where
Oh :: (forall c. (k :- (OneOf a b c))) -> Oh k
oh :: Oh ()
oh = Oh (inst `trans` oneOfEither)
It is clear to me this type should not be inhabited, but it is. If you have this then you can essentially prove that for any three types, two are the same. Lets pick particularly evil types
newtype First a b c = First {fromFirst :: a}
newtype Second a b c = Second {fromSecond :: b}
newtype Third a b c = Third {fromThird :: c}
Given a standard equality construction like
data a :==: b where
Refl :: a :==: a
coerce :: (a :==: b) -> a -> b
coerce Refl = id
coerce' :: (a :==: b) -> b -> a
coerce' Refl = id
we can show that of three types, two are the same like
data No where
No :: (forall d e f.
((Either (a :==: (First d e f)) (b :==: (First d e f))),
(Either (a :==: (Second d e f)) (b :==: (Second d e f))),
(Either (a :==: (Third d e f)) (b :==: (Third d e f)))))
-> No
makeOneOf :: (() :- OneOf a b c) -> Either (a :==: c) (b :==: c)
makeOneOf f = oneOf \\ f
no :: No
no = case oh of
Oh f -> No ((makeOneOf f),(makeOneOf f),(makeOneOf f))
this leads to an elegant unsafeCoerce
--infered type c1 -> c
unsafeCoerce
= case no of
No (Right x, Right y, _ ) -> fromFirst . (coerce x) . (coerce' y) . Second
No (_ , Right x, Right y) -> fromSecond . (coerce x) . (coerce' y) . Third
No (Right x, _ , Right y) -> fromFirst . (coerce x) . (coerce' y) . Third
No (Left x , Left y , _ ) -> fromFirst . (coerce x) . (coerce' y) . Second
No (_ , Left x , Left y) -> fromSecond . (coerce x) . (coerce' y) . Third
No (Left x , _ , Left y) -> fromFirst . (coerce x) . (coerce' y) . Third
which would work with only the first line--I know how Forall is actually implemented--but this definition should work with any way of defining forall using a tuple. My GHCi then lets me
λ: unsafeCoerce "hello world" :: Int
5188146770748711367
IncoherentInstances don't normally cause a loss of type safety (as far as I know), although they are still pretty terrible. I don't think it is unliqely though that other corners of haskell might produce the same problem--I'm think both ImplicitParams, and your reflection package as possibilities.