Haskell Documentation on Terminal [duplicate]
Asked Answered
M

4

23

Is it possible to get Haskell Documentation from Terminal or from ghci?

In Ruby I usually do

ri thefunc

In Perl I usually do

perldoc -f thefunc

Or I can get interactive help in Python.

How to do this kind of thing in Haskell? For example, if I want to get Documentation about [] or : on Terminal?


Update

I found this related thread, but I'm not sure if :i is the answer :-/ or is it?

*Main> :i []
data [] a = [] | a : [a]    -- Defined in GHC.Types
instance (Eq a) => Eq [a] -- Defined in GHC.Base
instance Monad [] -- Defined in GHC.Base
instance Functor [] -- Defined in GHC.Base
instance (Ord a) => Ord [a] -- Defined in GHC.Base
instance (Read a) => Read [a] -- Defined in GHC.Read
instance (Show a) => Show [a] -- Defined in GHC.Show
Marcel answered 6/7, 2011 at 3:58 Comment(1)
Usually you get data from the interactive terminal with :t, :i, :k and :bro.Ruy
B
12

What you want is called Hoogle. It's actually quite a bit cooler than most command-line doc tools, as it can look up functions by name or by type, and is pretty clever at working out types that are compatible but not exactly what you specified (e.g. you might search for a -> [a] and it will figure out that you might want a function with the type (Monad m) => a -> m a, the type you searched for is the same thing with the typeclass filled in).

Bannerman answered 6/7, 2011 at 4:33 Comment(1)
How do I use that on the command line or from inside ghci?Ctenophore
A
5

As this answer says, there's no way to get documentation from ghci. However, in Haskell, the types give you more information than Java (or obviously dynamically typed languages like Ruby and Python); they can be a hint about how the function works, and tell you how you can compose them.

In ghci, you can try :browse to view the types of all top-level functions, or with a package name as an argument, e.g. :browse Control.Monad. This can be very useful if you already know about a function, but aren't sure how to use it (otherwise, use Hoogle or Hayoo as others suggest). You can also use :t to get the type of an expression, or :i to get information about a typeclass.

EDIT -- I know this is a little opinionistic, but I think the presence of things like parametric types, etc., and decent "core" functions makes it a little easier to get away not reading documentation, at least compared to Java or C (maybe not so much Python or Ruby).

Ansilma answered 6/7, 2011 at 6:9 Comment(0)
T
4

I use Hoogle and Hayoo!.

Tremulant answered 6/7, 2011 at 5:57 Comment(0)
A
4

There'sa GHCi extension called "GHCi on Acid (GOA)":

http://www.haskell.org/haskellwiki/GHC/GHCi#GHCi_on_Acid

It's not exactly ri, but it's a convenient way to use Hoogle and other niceties from your REPL.

Ansermet answered 6/7, 2011 at 10:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.