haskell-names: Name resolution library for Haskell

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Warnings:

This package takes modules parsed with `haskell-src-exts`, resolves used names and annotates the parsed module with scoping information.


[Skip to Readme]

Properties

Versions 0.1, 0.1.1, 0.1.2, 0.2, 0.2.1, 0.3, 0.3.1, 0.3.2, 0.3.2.1, 0.3.2.2, 0.3.2.3, 0.3.2.4, 0.3.2.5, 0.3.2.6, 0.3.2.7, 0.3.2.8, 0.3.3, 0.3.3.1, 0.3.3.2, 0.4, 0.4.1, 0.5.0, 0.5.1, 0.5.2, 0.5.3, 0.6.0, 0.7.0, 0.8.0, 0.9.0, 0.9.0, 0.9.1, 0.9.2, 0.9.3, 0.9.4, 0.9.5, 0.9.6, 0.9.7, 0.9.8, 0.9.9
Change log CHANGELOG.md
Dependencies aeson (>=0.8.0.2 && <1.3), base (>=4 && <5), bytestring (>=0.10.4.0 && <0.11), containers (>=0.2 && <0.6), data-lens-light (>=0.1.2.1 && <0.2), filepath (>=1.1 && <1.5), haskell-src-exts (>=1.18 && <1.20), mtl (>=2.2.1 && <2.3), tagged (>=0.8.4 && <0.9), transformers (>=0.4.2.0 && <0.6), traverse-with-class (>=1.0.0.0 && <1.1), uniplate (>=1.5.1 && <1.7) [details]
License BSD-3-Clause
Author Philipp Schuster, Roman Cheplyaka, Lennart Augustsson
Maintainer Philipp Schuster
Category Language
Home page http://documentup.com/haskell-suite/haskell-names
Source repo head: git clone git://github.com/haskell-suite/haskell-names.git
Uploaded by PhilippSchuster at 2017-09-16T17:31:48Z

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for haskell-names-0.9.0

[back to package description]

haskell-names Build Status

haskell-names does name and module resolution for haskell-src-exts AST.

Namely, it can do the following:

Installation

If you're building a development version, then you might also need to install a development version of haskell-src-exts.

Environments

An environment is a map from module name to list of symbols the module exports. Symbols are for example types, classes, functions etc. We persist these lists in a JSON format. For example, here are a couple of entries from Prelude.names:

[
  {
    "name": "map",
    "entity": "value",
    "module": "GHC.Base"
  },
  {
    "name": "IO",
    "entity": "newtype",
    "module": "GHC.Types"
  },
  ...
]

As you see, each entity is annotated with the module where it was originally defined. Additionally, class methods, field selectors, and data constructors are annotated with the class or type they belong to.

haskell-names provides functions readSymbols and writeSymbols to read and write interface files.

Name resolution

The annotate function annotates the given module with scoping information.

Its essence is described in the article Open your name resolution.

Examples

The example in examples/HeadUsage.hs shows how you would find out if a Haskell modules given on stdin uses Prelude.head.

% cabal exec -- runghc examples/HeadUsages.hs
one = head [1]
^D
Prelude.head is used at stdin: (1:7) - (1:11)

% cabal exec -- runghc examples/HeadUsages.hs
import Prelude hiding (head)
import Data.Text

f = head (pack "foo")
^D
Congratulations! Your code doesn't use Prelude.head

The example in examples/ModuleExports.hs shows how the resolve function behaves. It expects to find examples/moduleexports.Example.hs and examples/moduleexports/Example/Internal.hs.

% cabal exec -- runghc examples/ModuleExports.hs
Only example: fromList [(ModuleName () "Example",[])]
Only internal: fromList [(ModuleName () "Example.Internal",[Value {symbolModule = ModuleName () "Example.Internal", symbolName = Ident () "details"}])]
Example & Internal: fromList [(ModuleName () "Example",[Value {symbolModule = ModuleName () "Example.Internal", symbolName = Ident () "details"}]),(ModuleName () "Example.Internal",[Value {symbolModule = ModuleName () "Example.Internal", symbolName = Ident () "details"}])]
Internal & Example: fromList [(ModuleName () "Example",[Value {symbolModule = ModuleName () "Example.Internal", symbolName = Ident () "details"}]),(ModuleName () "Example.Internal",[Value {symbolModule = ModuleName () "Example.Internal", symbolName = Ident () "details"}])]
Example after Internal: fromList [(ModuleName () "Example",[Value {symbolModule = ModuleName () "Example.Internal", symbolName = Ident () "details"}]),(ModuleName () "Example.Internal",[Value {symbolModule = ModuleName () "Example.Internal", symbolName = Ident () "details"}])]
Internal after Example: fromList [(ModuleName () "Example",[]),(ModuleName () "Example.Internal",[Value {symbolModule = ModuleName () "Example.Internal", symbolName = Ident () "details"}])]

API documentation

The core module you need is Language.Haskell.Names

Other modules are more experimental, less documented, and you probably don't need them anyway.

Known issues

See the list of all issues.

Maintainers

Philipp Schuster is the primary maintainer.

Adam Bergmark is the backup maintainer. Please get in touch with him if the primary maintainer cannot be reached.