Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to see the list of functions in a module, in GHCI?

Tags:

haskell

I find it handy in Python or Common Lisp that you can list a library's contents at runtime. Does Haskell have the same thing, in particular from a GHCI prompt?

like image 546
justinhj Avatar asked Nov 09 '09 03:11

justinhj


People also ask

How to define function in GHCi?

Simply type a let followed by a newline: let ⏎. Then fac 0 = 1 ⏎. Then fac n = n * fac (n-1) ⏎ ⏎ and you're done!

How to quit GHCi?

Quits GHCi. You can also quit by typing control-D at the prompt. Attempts to reload the current target set (see :load ) if any of the modules in the set, or any dependent module, has changed.

How to load file in GHCi?

GHCi is the interactive interface to GHC. From the command line, enter "ghci" (or "ghci -W") followed by an optional filename to load. Note: We recommend using "ghci -W", which tells GHC to output useful warning messages in more situations. These warnings help to avoid common programming errors.

What does GHCi mean in Haskell?

GHCi [1] is GHC's interactive environment that includes an interactive debugger (see The GHCi Debugger). GHCi can. interactively evaluate Haskell expressions. interpret Haskell programs. load GHC-compiled modules.


2 Answers

GHCi has a :browse command to list the contents of modules:

Prelude> :browse Data.List (\\) :: (Eq a) => [a] -> [a] -> [a] delete :: (Eq a) => a -> [a] -> [a] deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a] deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] elemIndex :: (Eq a) => a -> [a] -> Maybe Int ... Prelude> :help                     ...    :browse[!] [[*]<mod>]       display the names defined by module <mod>                                (!: more details; *: all top-level names) ... 
like image 74
sth Avatar answered Sep 19 '22 12:09

sth


Depending on exactly what information you intend to extract... If your version of GHCi supports tab-completion, then you can use that to list all of a namespace's available functions:

Prelude> :m +Data.List Prelude Data.List> Data.List.<PRESS TAB KEY HERE> Display all 109 possibilities? (y or n) <PRESS n> Prelude Data.List> Data.List.un<PRESS TAB KEY HERE> Data.List.unfoldr  Data.List.unlines  Data.List.unzip3   Data.List.unzip6    Data.List.union    Data.List.unwords  Data.List.unzip4   Data.List.unzip7    Data.List.unionBy  Data.List.unzip    Data.List.unzip5    
like image 23
Mark Rushakoff Avatar answered Sep 18 '22 12:09

Mark Rushakoff