Phyx
Phyx

Reputation: 2697

Determine ModuleName of loaded target

I was wondering how do you determine the ModuleName of the file you've just loaded in ghc using the API.

If you look at the Documentation of the API they always assume you know the module name before you load the file in.

I have tried top sorting the dependency graph and picking the last module there, but that doesn't seem to always return the file that was loaded in.

The way I have been able to do it previously was to modify the GHC source code to store this information in the HscEnv.

It would be nice if the call to load would return it, But there surely must be a way to do it already since GHCi knows this when it loads a file.

Upvotes: 3

Views: 119

Answers (1)

Daniel
Daniel

Reputation: 27549

The haskell-src-exts package has a parseFile function with type parseFile :: FilePath -> IO (ParseResult Module). The Module type has a field for the module's name.

Upvotes: 1

Related Questions