I'm using Haskell 2010.1.0.0.1 with GHC 6. Typing :t
at the GHCi prompt followed by the name of a function shows us the type of the function. Is there a way to view the function definition as well?

- 13,850
- 9
- 56
- 64

- 653
- 1
- 5
- 4
-
4Update Nov 2018: we are currently at GHC 8.6 and that functionality is still not available. – salva Nov 15 '18 at 11:17
3 Answers
Not currently.
The closest command to what you want is :info
:info name ...
Displays information about the given name(s). For example, if name is a class, then the class methods and their types will be printed; if name is a type constructor, then its definition will be printed; if name is a function, then its type will be printed. If name has been loaded from a source file, then GHCi will also display the location of its definition in the source.
For types and classes, GHCi also summarises instances that mention them. To avoid showing irrelevant information, an instance is shown only if (a) its head mentions name, and (b) all the other things mentioned in the instance are in scope (either qualified or otherwise) as a result of a :load or :module commands.
like so:
Prelude> :info ($)
($) :: (a -> b) -> a -> b -- Defined in GHC.Base
infixr 0 $
You can though, see the source for identifiers generated by the haddock tool, on Hackage.
Note that "?src" is a valid command in lambdabot, on the #haskell IRC channel, and does what you'd expect.
> ?src ($)
> f $ x = f x

- 137,316
- 36
- 365
- 468
-
Thanks a lot. I have only recently started learning Haskell and didn't know about lambdabot. This works perfectly well as an alternative. – franco hades Apr 26 '11 at 08:00
-
1@franco hades: I believe lambdabot can also be installed locally, from Hackage, so you don't need to be on IRC to use it (unless you want to, #haskell is a nice channel). – C. A. McCann Apr 26 '11 at 13:46
-
Very cool — it also says that you can embed lambdabot in ghci! The instructions aren't very clear, however. – stites Jan 14 '16 at 14:43
-
if not then why, what prevents and when it will be available ? – Daniil Iaitskov Dec 18 '19 at 00:31
I don't think so. You can use :i
for a little bit more information (more useful for infix operators and data constructions, etc.), but not the definition:
ghci> :i repeat
repeat :: a -> [a] -- Defined in GHC.List
You can use hoogle to quickly find the documentation for a standard library function, which on the right has a link to go to the source. It's still a few clicks away though.

- 59,485
- 12
- 145
- 204
Nope, can't do that. Some fun things you, the Haskell beginner, can do:
- On the HTML haddock documents, click on "source"... study the source.
:browse
to find all of the definitions exported by a module- Use
:help
for the obvious result - use the web interface of hoogle to search for functions, or install hoogle locally!
- ?
- Profit!

- 64,245
- 7
- 109
- 166
-
1`:browse` does not give you the definitions. It gives you a list of the module's functions and their types. – Tshimanga Nov 09 '15 at 19:21
-
Would you be happier if I said "all the symbols" or "top level definitions"? Feel free to edit. – Thomas M. DuBuisson Nov 09 '15 at 19:39