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.
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.
: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.
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
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.