Wednesday, December 23, 2015

A new version of haskell-names is on hackage. haskell-names does name resolution for modules parsed with haskell-src-exts.
The API is very different in this new version. The most important type is now:

type Environment = Map ModuleName [Symbol]

An environment is a map from module name to list of symbols the module exports. A symbol is for example a value, a class, a method or a type. You use functions from Data.Map to work with environments, for example to create an empty environment.
Then there are two functions that work on environments (type class constraints omitted for brevity):

resolve takes a list of modules and an environment, finds the lists of symbols each of the given modules exports and inserts them into the given environment. annotate takes an environment and a module AST and annotates the given AST with scoping information. Scoping information is for example the origin of an imported or local name or name resolution errors.
You load and persist environments with two functions:

You have to come up with your own system to remember which file name corresponds to which module name. Internally the two functions use aeson to serialize symbols to json.
Finally, for quick experimentation there is a function

loadBase :: IO Environment

that gives you a base environment very similar to GHC’s base. An example for a program that uses the new API is on the github page.