16

Is there a command in Haskell which displays (or get as a list of) all the user defined functions which have been loaded/defined in the GHCi? Thanks

artella
  • 5,068
  • 4
  • 27
  • 35

2 Answers2

23

To see bindings you've made at the ghci prompt (e.g. with let or <-), try :show bindings.

If you've loaded some modules, you can use :show modules to get the names of loaded modules and then :browse ModuleName to list everything in scope from that module.

Ben Millwood
  • 6,754
  • 24
  • 45
  • Hi, I tried that but it did not work for me. I am using WinGHCi and I loaded the functions via the ':load' function as outlined in the post [Haskell : loading ALL files in current directory path](http://stackoverflow.com/questions/10268692/haskell-loading-all-files-in-current-directory-path). However when I try ':show bindings' it just says 'it :: Int = 7' because I invoked 'addNumber2 3 4' last. Thanks – artella Apr 24 '12 at 09:17
  • I edited in instructions for what you do if there are modules. – Ben Millwood Apr 24 '12 at 11:05
  • Hi, :browse requires knowledge of which module has been loaded. Is there a way of doing this without requiring knowledge of which modules have been loaded? (see also comment below). Thanks. – artella Apr 24 '12 at 11:16
  • I don't think so, unless you can parse the output of `:show modules`. – Ben Millwood Apr 24 '12 at 17:41
10

When in ghci, use :browse or just :bro after loading the file. You may also browse unloaded modules via :browse Foo.Bar.Baz.

Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380
  • `:br` now resolves to `:break`, for browsing, you need `:bro`. – Daniel Fischer Apr 22 '12 at 21:44
  • 14
    `:dawg` should be a ghci synonym for `:bro` – Dan Burton Apr 23 '12 at 00:47
  • Hi I tried this, but in WinGHCi ':browse' does nothing! I loaded the files as outlined in the post [Haskell : loading ALL files in current directory path](http://stackoverflow.com/questions/10268692/haskell-loading-all-files-in-current-directory-path) – artella Apr 24 '12 at 09:18
  • Did you try `:browse ModuleName`? – Ben Millwood Apr 24 '12 at 11:06
  • Ah I didnt realise that you have to specify the module name. But suppose I have scripts to load different modules. Then is there a way to see all the functions which have been loaded from the various modules, without requiring knowledge of which modules have been loaded? Thanks – artella Apr 24 '12 at 11:15
  • @artella In ghci, `:browse` with no arguments shows the bindings defined in the currently loaded module(s). Perhaps you should upgrade from hugs. =) – Daniel Wagner Apr 24 '12 at 15:02