开发者

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

I find it handy in Python or Common Lisp that you can list a library's contents at runtime. Does Haskell ha开发者_开发技巧ve the same thing, in particular from a GHCI prompt?


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


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   
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜