Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View non-exposed library functions while developing in Haskell

I made a mistake in another question that could have been solved by viewing

:t myfunctionofinterest

for a function I was using in a library.

However, when I am in my project root, and run

$ stack ghci

And my Main.hs has:

import MyLib

And my module does:

module MyLib {
  bunchOfFunctions -- but not myfunctionofinterest
} where

import SomeDB.ModuleThatExposes -- myfunctionofinterest

myfunc :: IO ()
myfunc = do
  myfunctionofinterest a b c -- place where I misuse myfunctionofinterest and could have used :t on it to see it had 3 args

I can't :t myfunctionofinterest in the main since it's not exposed, nor does Import MyLib.myfunctionofinterest explicitly help, since it was something defined in an import. While I know I could expose it then check it, :a to compile, and then edit the lib to hide it again, is there anything that allows that more quickly and directly?

This seems like it must be a common pattern. What do you do when you need to check the type of something used in a library as you develop?

like image 486
Mittenchops Avatar asked Aug 28 '16 16:08

Mittenchops


1 Answers

Quoting the GHCi docs:

The :module command provides a way to do two things that cannot be done with ordinary import declarations:

  • :module supports the * modifier on modules, which opens the full top-level scope of a module, rather than just its exports.

The additional * makes GHCi load the bytecode version of the module. This will not be as performant, but you'll get access to unexported bindings.

Example:

λ> :m *MyLib
λ> :t myfunctionofinterest

If you get

module 'MyLib' is not interpreted; try ':add *MyLib' first

you may have to do :load first (the advice about :add doesn't always do the trick):

λ> :l *MyLib
λ> :m *MyLib
λ> :t myfunctionofinterest
like image 82
chi Avatar answered Oct 07 '22 13:10

chi