Here is the ScopedTypeVariables version I thought should work but indeed it doesn't, although I don't fully understand why. Is it because GHC instantiates `val` and then tries to generalize again, but fails since the polymorphic argument to `reify` is very ambiguous? And is this the intended behavior?
{-# Language ScopedTypeVariables #-}
{-# Language RankNTypes #-}
{-# Language TypeApplications #-}
{-# Language MultiParamTypeClasses #-}
{-# Language FlexibleContexts #-}
{-# Language AllowAmbiguousTypes #-}
class Reifies s a
reify :: forall a r. a -> (forall s. Reifies s a => r) -> r
reify _ _ = undefined
reflect :: forall s a. Reifies s a => a
reflect = undefined
example = reify 5 val
where
val :: forall s. Reifies s Integer => Integer
val = reflect @s + reflect @s