[Haskell-cafe] Is it possible to get the information of instances of a type?
Brent Yorgey
byorgey at seas.upenn.edu
Wed Oct 26 19:34:15 CEST 2011
On Wed, Oct 26, 2011 at 09:15:41AM -0700, Nathan Howell wrote:
> On Wed, Oct 26, 2011 at 6:53 AM, Magicloud Magiclouds <
> magicloud.magiclouds at gmail.com> wrote:
>
> > But in Haskell, could I write a code to list the classes that a type
> > instanced?
> > TemplateHaskell as well.
> >
>
> It's possible with TemplateHaskell. Look at classInstances and the ClassI
> data constructor.
>
> http://haskell.org/ghc/docs/7.0.4/html/libraries/template-haskell-2.5.0.0/Language-Haskell-TH.html#v:classInstances
No, this lists all the instances of a class. OP asked for the classes
of which a given type is an instace.
Presumably it is possible, since Haddock does it! In the
documentation generated for a type it lists classes of which the type
is an instance. So you might want to look at how Haddock does it. I
suspect the only way is through the GHC API.
-Brent
More information about the Haskell-Cafe
mailing list