Frage

Is there an equivalent of python dir for haskell ghci?

In the python interpreter, dir shows the defined symbols. I would like to use something similar also in Haskell, in order to explore the functions provided by the imported modules.

me@mine$ python
>>> from pickle import *
>>> dir()
['APPEND', 'APPENDS', 'BINFLOAT', 'BINGET', 'BININT', 'BININT1', 'BININT2', 'BINPERSID', 'BINPUT', 'BINSTRING', 'BINUNICODE', 'BUILD', 'DICT', 'DUP', 'EMPTY_DICT', 'EMPTY_LIST', 'EMPTY_TUPLE', 'EXT1', 'EXT2', 'EXT4', 'FALSE', 'FLOAT', 'GET', 'GLOBAL', 'HIGHEST_PROTOCOL', 'INST', 'INT', 'LIST', 'LONG', 'LONG1', 'LONG4', 'LONG_BINGET', 'LONG_BINPUT', 'MARK', 'NEWFALSE', 'NEWOBJ', 'NEWTRUE', 'NONE', 'OBJ', 'PERSID', 'POP', 'POP_MARK', 'PROTO', 'PUT', 'PickleError', 'Pickler', 'PicklingError', 'REDUCE', 'SETITEM', 'SETITEMS', 'SHORT_BINSTRING', 'STOP', 'STRING', 'TRUE', 'TUPLE', 'TUPLE1', 'TUPLE2', 'TUPLE3', 'UNICODE', 'Unpickler', 'UnpicklingError', '__builtins__', '__doc__', '__name__', '__package__', 'dump', 'dumps', 'load', 'loads']
War es hilfreich?

Lösung 2

This summarizes the answers in the comments like you suggested.

You can use the :browse command without arguments in ghci to view all values imported from the most recently imported module. If you call it when you enter ghci it will output all values imported by the Prelude. You can also use :browse <ModuleName> to browse a module that you have not yet imported.

This, however, does not work for values that you defined yourself in ghci. To access those, use tab completion, like YellPika suggested.

Andere Tipps

AFAIK, there is no direct equivalent of dir in Haskell. If you just want to browse definitions in GHCI, then all you need to do is hit tab.

Ex:

ghci> [tab]
Display all 470 possibilities? (y or n) [y]
{spits everything that's currently in scope}

ghci> Prelude.[tab]
Display all 235 possibilities? (y or n) [y]
{spits out everything in the Prelude namespace}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top