Haskell : display/get list of all user defined functions
Asked Answered
S

2

17

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

Sullivan answered 22/4, 2012 at 21:2 Comment(0)
T
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.

Thyroiditis answered 23/4, 2012 at 0:1 Comment(4)
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. However when I try ':show bindings' it just says 'it :: Int = 7' because I invoked 'addNumber2 3 4' last. ThanksSullivan
I edited in instructions for what you do if there are modules.Thyroiditis
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.Sullivan
I don't think so, unless you can parse the output of :show modules.Thyroiditis
C
10

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

Chappelka answered 22/4, 2012 at 21:4 Comment(6)
:br now resolves to :break, for browsing, you need :bro.Carrera
:dawg should be a ghci synonym for :broDecimal
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 pathSullivan
Did you try :browse ModuleName?Thyroiditis
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? ThanksSullivan
@Sullivan In ghci, :browse with no arguments shows the bindings defined in the currently loaded module(s). Perhaps you should upgrade from hugs. =)Chappelka

© 2022 - 2024 — McMap. All rights reserved.