Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I figure out which of my imports are from in Haskell?

Tags:

haskell

I have a bunch of imports in my package and need to sort out which ones are coming from a specific package (MissingH). I'm not sure how to do this other than by searching for each on Hoogle. Is there a way to do this programmatically or at the command line by just scanning my package's files?

Here's my list of imports (from all files of my package):

import           Control.Arrow
import           Control.Exception      (assert)
import           Control.Monad          (unless)
import           Control.Monad.Except
import           Control.Monad.Zip
import           Control.Applicative
import           Data.Monoid
import           Data.List
import           Data.List.Split        (splitOn)
import qualified Data.Map               as M
import           Data.Maybe
import           Text.Printf            (printf)
import           Data.Char              (toUpper)
import           Data.String.Utils      (replace)

import Data.Char (chr, ord)
import Data.List (sort)

import Control.Applicative
import Data.Monoid
import Data.Char
import Data.List
import Data.List.Split          (chunksOf)
import Data.String.Utils        (replace)
import Text.Printf              (printf)
like image 406
orome Avatar asked Oct 10 '18 14:10

orome


People also ask

What is module Main where in Haskell?

A Haskell module is a collection of related functions, types and typeclasses. A Haskell program is a collection of modules where the main module loads up the other modules and then uses the functions defined in them to do something. Having code split up into several modules has quite a lot of advantages.

What does prelude mean in Haskell?

From HaskellWiki. Prelude is a module that contains a small set of standard definitions and is included automatically into all Haskell modules.

What is a qualified import?

A qualified import allows using functions with the same name imported from several modules, e.g. map from the Prelude and map from Data.

How do I load a file into Haskell?

Basic Haskell Commands :quit (or :q) :load [filename] (or :l [filename]) :reload -- reload the current file set after you'ved edited it (or :r) :cd -- change to another directory.


1 Answers

You can ask GHC where it thinks a module comes from (if you have a package already installed providing that module).

% ghc-pkg find-module Data.Maybe
/usr/local/lib/ghc-8.2.2/package.conf.d
    base-4.10.1.0
/home/dmwit/.ghc/x86_64-linux-8.2.2/package.conf.d
    (no packages)

You can probably cook up a few quick scripts to automate calling this and cover 99.9% of the code people actually write. You might also like to abuse graphmod -- use it to create a module graph, then ignore all the structure of the graph and just iterate over the list of module names it discovers for you and call ghc-pkg on each.

...but it's probably going to be much quicker to just delete MissingH from the dependencies in your cabal file (you are using a build tool like stack or cabal, right??) and see which imports GHC complains about.

like image 75
Daniel Wagner Avatar answered Nov 15 '22 07:11

Daniel Wagner