Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Documentation on Terminal [duplicate]

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
like image 322
Arie Avatar asked Jul 06 '11 03:07

Arie


4 Answers

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

like image 128
Chuck Avatar answered Oct 30 '22 12:10

Chuck


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

like image 24
gatoatigrado Avatar answered Oct 30 '22 12:10

gatoatigrado


I use Hoogle and Hayoo!.

like image 41
Johannes Weiss Avatar answered Oct 30 '22 12:10

Johannes Weiss


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.

like image 31
Michael Kohl Avatar answered Oct 30 '22 10:10

Michael Kohl