reifyInstances nm tys returns a list of all visible instances (see below for "visible")
of nm tys. That is,
if nm is the name of a type class, then all instances of this class at the types tys
are returned. Alternatively, if nm is the name of a data family or type family,
all instances of this family at the types tys are returned.
Note that this is a "shallow" test; the declarations returned merely have
instance heads which unify with nm tys, they need not actually be satisfiable.
reifyInstances ''Eq [ TupleT 2 `AppT` ConT ''A `AppT` ConT ''B ] contains
the instance (Eq a, Eq b) => Eq (a, b) regardless of whether A and
B themselves implement Eq
reifyInstances ''Show [ VarT (mkName "a") ] produces every available
instance of Show
There is one edge case: reifyInstances ''Typeable tys currently always
produces an empty list (no matter what tys are given).
In principle, the *visible* instances are
* all instances defined in a prior top-level declaration group
(see docs on newDeclarationGroup), or
* all instances defined in any module transitively imported by the
module being compiled
However, actually searching all modules transitively below the one being
compiled is unreasonably expensive, so reifyInstances will report only the
instance for modules that GHC has had some cause to visit during this
compilation. This is a shortcoming: reifyInstances might fail to report
instances for a type that is otherwise unusued, or instances defined in a
different component. You can work around this shortcoming by explicitly importing the modules
whose instances you want to be visible. GHC issue #20529
has some discussion around this.