haskell-namesis on hackage.
haskell-namesdoes name resolution for modules parsed with
The API is very different in this new version. The most important type is now:
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
type Environment = Map ModuleName [Symbol]
Data.Mapto 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 :: [Module s] -> Environment -> Environment annotate :: Environment -> Module s -> Module (Scoped s)
resolvetakes 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.
annotatetakes 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
readSymbols :: FilePath -> IO [Symbol] writeSymbols :: FilePath -> [Symbol] -> IO ()
aesonto serialize symbols to json.
Finally, for quick experimentation there is a function
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.
loadBase :: IO Environment