Using the GHC API: pretty printing with qualified names

Thomas Schilling nominolo at
Wed Nov 17 15:21:46 EST 2010

On 17 November 2010 19:21, JP Moresmau <jpmoresmau at> wrote:
> Hello, I'm the maintainer for EclipseFP, which involves using the scion
> library and the GHC API to provide IDE functionality. I have a little issue
> that no doubt stems from me not understanding the GHC API well, and I would
> be grateful for any light on the matter.
> I'm trying to give the user the possibility to jump to the definition of a
> symbol in the source file. You click on the name of a function and you're
> send to the module where it's defined. So I have an AST, and somewhere down
> the line I have an Id object representing that function call. Then I just
> use ppr alwaysQualify id to get the fully qualified name of the function,
> and I can then use the module name to retrieve the source file etc. This
> works well in cases, but not in others. It will sound silly to the gurus on
> the list, but it's when the function has generics that it doesn't work. So a
> function with a type class in its type signature will never be printed
> qualified. It kinda like makes sense because I suppose some work has been
> done so that it represents the function with proper types, etc., but how can
> I get back to the original Id? How can I get back from that unqualified Id
> to the qualified Id representing the function in the original module? I've
> been looking round Name and OccName and all that but I'm not sure really
> what I'm looking for.
> Hope I'm making sense!!
> Thanks!

Note that typeclass methods all live in a top-level namespace.
Qualified names are used to disambiguate between multiple names which
this is not necessary for method names.

I presume when you want to jump to the definition of a method, you
want to do something special anyway.  You probably want to jump to the
implementation of the method for the type at which it is used.  If it
is used polymorphically you cannot do this (there is no statically
known definition), so you could just display its type or a list of all
known implementations.

To find out the type at which a polymorphic or overloaded identifier
is used, you have to interpret type applications (HsWrap) and
abstractions (AbsBind).

The GHC API provides access to all imported instances, but they
probably won't have source code annotations.  Such a database must be
created separately.


/ Thomas

Push the envelope. Watch it bend.

More information about the Glasgow-haskell-users mailing list