Lii
Lii

Reputation: 12112

Get module contents

The :browse, :info and :type GHCi commands are very convenient.

Is it possible to get the same information programmaticaly in a Haskell program? That is, to get the exported functions from a module, the types of stuff, etc.

Upvotes: 6

Views: 225

Answers (3)

Lii
Lii

Reputation: 12112

Daniel Fischer commented:

You can use the GHC API. I'm not aware of a simpler way.

Seems to be fiddly but to work fine. And I guess this is how :info works in GHCi. Thanks for the suggestion.

Upvotes: 0

epsilonhalbe
epsilonhalbe

Reputation: 15967

for getting functions of a module at compile time - the language-haskell-extract package could be interesting to you. It helps you extracting functions according to a regular expression.

http://hackage.haskell.org/package/language-haskell-extract-0.2.1

Upvotes: 3

amindfv
amindfv

Reputation: 8448

:browse - when a Haskell program is compiled, no (useful) information is kept about which module something came from, so your program wouldn't be able to access that information.

:type - Unless you're using Data.Typeable, types aren't visible at all at runtime. Types in Haskell are mostly for the compiler to check to correctness/safety of code.

:info - See above.

Upvotes: 5

Related Questions