It is hard to say what exactly you are asking here. You can select a specific type T , deserialize the ByteString and save it to AnyNode . This does not make the AnyNode user much good, though - you still chose T , after all. If it weren’t for the Typeable restriction, the user couldn’t even say what the type is (so let's get rid of the Typeable restriction because it makes things more messy). Perhaps what you want is universal, not existential.
Divide Serialize into two classes - name them Read and Show - and simplify them a bit (for example, Read cannot fail).
So we have
class Show a where show :: a -> String class Read a where read :: String -> a
We can create an existential container for the Show -able value:
data ShowEx where ShowEx :: forall a. Show a => a -> ShowEx
But, of course, ShowEx is isomorphic to String , so that doesn't make much sense. But keep in mind that existential for Read has an even smaller point:
data ReadEx where ReadEx :: forall a. Read a => a -> ReadEx -- non-GADT: data ReadEx = forall a. Read a => ReadEx a
When I give you ReadEx - ie ∃a. Read a *> a ∃a. Read a *> a - this means that you have a value of some type, and you do not know what a type is, but you can String into another value of the same type. But you can’t do anything about it! Read only creates a s, but that does not help you if you do not know what a .
What you may need with Read will be the type that allows you to select the caller, i.e. universal. Sort of
newtype ReadUn where ReadUn :: (forall a. Read a => a) -> ReadUn -- non-GADT: newtype ReadUn = ReadUn (forall a. Read a => a)
(Like ReadEx , you can do ShowUn - ie ∀a. Show a => a - and that would be just as useless.)
Note that ShowEx is essentially a Show argument - that is, show :: (∃a. Show a *> a) -> String - and ReadUn is essentially the return value of Read - i.e. read :: String -> (∀a. Read a => a) .
So what do you ask for, existential or universal? You can, of course, do something like ∀a. (Show a, Read a) => a ∀a. (Show a, Read a) => a or ∃a. (Show a, Read a) *> a ∃a. (Show a, Read a) *> a , but you are not very good here either. The real problem is the quantifier.
(I asked a question a while ago, where I spoke about this in a different context.)