Currently, the GHC cannot create an instance of Typeable or any other instance for (,) :: Constraint -> Constraint -> Constraint . A constructor of type (,) has only * -> * -> * . There is no type constructor for such products Constraint -> Constraint -> Constraint . The constructor (,) overloaded to build both tuples and Constraint s products, but does not have an appropriate type constructor when used to create a Constraint s product.
If we had a type constructor for Constraint products, we could define an instance as follows. To do this, we will pretend that (,) also a type constructor with the form (,) :: Constraint -> Constraint -> Constraint . To define an instance for it, we will use KindSignatures and import GHC.Exts.Constraint to be able to explicitly talk about the types of constraints
{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE KindSignatures #-} import GHC.Exts (Constraint) import Data.Typeable deriving instance Typeable ((,) :: Constraint -> Constraint -> Constraint)
If we do this now, it will result in the following error due to the type constructor of type (,) .
The signature specified kind `Constraint -> Constraint -> Constraint', but `(,)' has kind `* -> * -> *' In the stand-alone deriving instance for `Typeable ((,) :: Constraint -> Constraint -> Constraint)'
The constraints package also works with constraint products and includes the following note .
due to a hack for type (,) in the current version of GHC, we canβt actually create instances for (,) :: Constraint -> Constraint -> Constraint
I assume Edward Kmett's hack is referring to constructor overloading (,) for Constraint without an appropriate type constructor.