ImpredicativeTypes & Existentials

What you’re looking for are first class existential types:

If Haskell had that, then you could write your desired function as follows:

newtype AnyFn = MkAnyFn (exists a b. (Show a, Show b) /\ Fn a b)
toAnyFns :: [exists a b. (Show a, Show b) /\ Fn a b] -> [AnyFn]

And you might not even need the AnyFn data type at all.

Also, the AnyFn type should be pretty much equivalent to your original AnyFn type that uses ExistentialQuantification, but I saw somewhere in the GHC proposal that these two features are not yet designed to work well together.

2 Likes