[Haskell-cafe] Is it possible to print out types of instances in
scope
Lemmih
lemmih at gmail.com
Sun Jan 16 13:47:17 EST 2005
On Sun, 16 Jan 2005 10:07:14 -0800, Jeremy Shaw
<jeremy.shaw at linspireinc.com> wrote:
> At Sun, 16 Jan 2005 12:09:43 +0100,
> Lemmih wrote:
> >
> > On Sun, 16 Jan 2005 00:13:08 -0800, Jeremy Shaw
> > <jeremy.shaw at linspireinc.com> wrote:
> > > Hello,
> > >
> > > Is it possible to write a function that would display all the instances
> > > of a class currently in scope[1]?
> > >
> > > For example, for 'Show a' it should output something like:
> > >
> > > The instances of 'Show a' currently in scope are:
> > > Show Int
> > > Show Float
> > > Show Char
> > > Show ...
> >
> > In GHC 6.3:
> > Prelude> :i Show
> > class Show a where
> > showsPrec :: Int -> a -> String -> String
> > show :: a -> String
> > showList :: [a] -> String -> String
> > -- Imported from `GHC.Show'
> > instance Show IOMode -- Imported from `GHC.IOBase'
> > instance Show IOException -- Imported from `GHC.IOBase'
> > instance Show IOErrorType -- Imported from `GHC.IOBase'
> > instance Show HandleType -- Imported from `GHC.IOBase'
> > [...]
>
> Neat! Is there some way I can get access to that information from
> within my program ? Maybe something like:
>
> import Language.Haskell.TH.Syntax
> instancesOf :: Name -> [Type]
There's no way you can access that information afaik.
--
Friendly,
Lemmih
More information about the Haskell-Cafe
mailing list