determining the origin of imported symbols

17 views
Skip to first unread message

Erik Rantapaa

unread,
Jul 24, 2014, 4:29:03 AM7/24/14
to haskel...@googlegroups.com
Hi everyone,

I looking for a way to analyze Haskell source to determine which module each imported symbol comes from. My goal is to transform source code like this:

    import Data.List
    ...
    main = do
      nums <- fmap (map read . words) getLine :: IO [Int]
      print $ sort nums

to code like this:

    import qualified Prelude as B
    import qualified Data.List as A
    ...
    main = do
      nums <- B.fmap (B.map B.read B.. B.words) B.getLine :: B.IO [B.Int]
      B.print B.$ A.sort nums

That is, I want to qualify all imported symbols with a module alias.

Can anyone suggest modules or programs I should look at?

Thanks,
ER

JP Moresmau

unread,
Jul 24, 2014, 5:06:37 AM7/24/14
to Erik Rantapaa, haskel...@googlegroups.com
BuildWrapper doesn't do the transformation, but it resolves all symbols to build a usage map, so it would tell you that Data.List.sort is used at line xxx, using the GHC API. So have a look at around https://github.com/JPMoresmau/BuildWrapper/blob/master/src/Language/Haskell/BuildWrapper/API.hs#L239. BuildWrapper takes the GHC AST, transforms it into a JSON structure, and extracts all usage information. There is also an import reorganization function that may be useful.

JP


_______________________________________________
Haskell-Cafe mailing list
Haskel...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe




--
JP Moresmau
http://jpmoresmau.blogspot.com/

Roman Cheplyaka

unread,
Jul 24, 2014, 5:11:20 AM7/24/14
to Erik Rantapaa, Haskell Cafe
Hi Erik,

haskell-names (https://github.com/haskell-suite/haskell-names) will help you
here.

* Erik Rantapaa <eran...@gmail.com> [2014-07-24 01:29:03-0700]
signature.asc

Daniel Trstenjak

unread,
Jul 24, 2014, 5:17:09 AM7/24/14
to haskel...@haskell.org

Hi Erik,

> Can anyone suggest modules or programs I should look at?

hsimport[1] and especially vim-hsimport[2] might be of help.


Greetings,
Daniel

[1] https://github.com/dan-t/hsimport
[2] https://github.com/dan-t/vim-hsimport

Eyal Lotem

unread,
Jul 24, 2014, 6:53:59 AM7/24/14
to haskel...@googlegroups.com, Erik Rantapaa
There's also ghc's -ddump-minimal-imports which might help you.


--
You received this message because you are subscribed to the Google Groups "Haskell-cafe" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-cafe...@googlegroups.com.
To post to this group, send email to haskel...@googlegroups.com.
Visit this group at http://groups.google.com/group/haskell-cafe.
For more options, visit https://groups.google.com/d/optout.



--
Eyal

Erik Rantapaa

unread,
Jul 24, 2014, 1:56:15 PM7/24/14
to haskel...@googlegroups.com, eran...@gmail.com
Thanks, everyone, for all of the suggestions!
Reply all
Reply to author
Forward
0 new messages