concat
concat

Reputation: 3187

GHC API: finding implementations of instance functions

I'm writing a symbolic execution engine for Haskell using GHC, and often I need to find the instance implementations of various functions in the program. However, after leafing through many ASTs produced by the typechecker, I can't see any way to tie a function call to its implementation in an instance block. The AST doesn't have the information to support the obvious solution of matching the Unique keys. Unlike top-level function definitions, none of the Uniques in the instance function binding match the Unique of the callsite. For example, in this simple program:

module M where
  class A a where
    foo :: a b -> b

  newtype Box a = Box a
  instance A Box where
    foo (Box a) = a

  bar = foo (Box ())

in the body of bar, foo has unique id rrZ. Within the HsBind of the instance definition, there are the following varName-varUnique pairs:

Since none of them match the callsite, I've resorted to an indirect method of matching the type at the callsite against all the types that have the same name, but this requires me to write separate logic for instances from top-level functions. Is there a unified way to find the implementation of some function?

Upvotes: 4

Views: 75

Answers (0)

Related Questions