This can't really be done reliably with type synonyms. You need either existential types or rank-n types.
The problem is that Haskell allows type synonyms to be fully intersubstitutable. I.e., when you define type Baz a b = Foo p a b
, then in every context where you have Foo p a b
, you would be allowed to use Baz a b
, and vice-versa. So for example, if you had a function of this type:
f1 :: Foo Something a b -> Whatever Something b a
Then because of substitutability, that'd be the same type as this:
f1 :: Baz a b -> Whatever Something b a
And as this:
f1 :: Foo p a b -> Whatever Something b a
...which then you could specialize to this:
f1 :: Foo SomethingElse a b -> Whatever Something b a
So, what can you do? One is to define an existential wrapper type:
{-# LANGUAGE ExistentialTypes #-}
data Baz a b = forall p. Baz (Foo p a b)
Alternative way of doing the same thing:
{-# LANGUAGE GADTs #-}
data Baz a b where
Baz :: Foo p a b -> Baz a b
Second way you could go: rank-n types and continuation-passing style:
{-# LANGUAGE RankNTypes #-}
-- To consume one of these, you pass a "callback" function to `runBaz`,
-- which is not allowed to restrict the type variable `p`.
newtype Baz a b = Baz { runBaz :: forall p r. (Foo p a b -> r) -> r }
makeBaz :: Foo p a -> Baz a b
makeBaz foo = Baz ($foo)
Third way, which you've attempted and (I'm told) doesn't work very well: type synonyms + impredicative types (which are required to get forall
synonyms to occur as type arguments in many cases).