10

I joined a project. The code base is new for me. I am interested in a module, which is used in code base and it is imported from a dependency. The module is not defined in the project.

Is there an automatic / easy way to figure out what library provides the module I am interested in?

Lot's of dependencies are proprietary and hoogle cannot help me with that.

leftaroundabout
  • 117,950
  • 5
  • 174
  • 319
Daniil Iaitskov
  • 5,525
  • 8
  • 39
  • 49

1 Answers1

12

You can use the ghc-pkg find-module command:

$ ghc-pkg find-module Data.List
/opt/ghc/8.10.1/lib/ghc-8.10.1/package.conf.d
    base-4.14.0.0
/home/simon/.ghc/x86_64-linux-8.10.1/package.conf.d
    (no packages)

In a stack project that uses its own package DBs, you'd have to wrap the command in stack exec:

$ stack exec -- ghc-pkg find-module Data.Fix
/home/simon/.stack/programs/x86_64-linux/ghc-8.6.5/lib/ghc-8.6.5/package.conf.d
    (no packages)
/home/simon/.stack/snapshots/x86_64-linux/0d371d66c37115ac97bac3fbbc5cc7b3718e197710ba11b06c7e9d7fcf441a3f/8.6.5/pkgdb
    data-fix-0.2.0
/home/simon/src/dhall-haskell/.stack-work/install/x86_64-linux/0d371d66c37115ac97bac3fbbc5cc7b3718e197710ba11b06c7e9d7fcf441a3f/8.6.5/pkgdb
    (no packages)

I'm not sure how to best use ghc-pkg in a cabal project.

sjakobi
  • 3,546
  • 1
  • 25
  • 43
  • 1
    `ghc-pkg find-module Data.List -f ~/.cabal/store/ghc-$version/package.db` is a start, though I think it will print multiple versions of the same library if they're installed. – HTNW Jul 20 '20 at 16:10