views:

644

answers:

4

Is there a descriptive listing of common Haskell functions in prelude and some of the core libraries such as Data.List and Data.Char?

I am just learning Haskell and I find myself frequently performing time-inefficient searches for functions that I know exist but for which I have forgotten the name. Such searches tend to distract my focus from the material that I am studying. Ideally I'd like a single listing (or one listing per library) that displays:

  • Function name
  • Type definition
  • Very brief explanation of purpose

I'm familiar with Justin Bailey's The Haskell Cheatsheet, but I'm looking for something with less explanation and more comprehensive coverage of available core functions. Miloslav Nic's Haskell Reference is very useful, but is spread out with one function per web page and function name lists per library. None of the cheat sheets at cheat-sheets.org really fit the bill. Obviously the Haskell source itself can be useful, but it can be difficult to search. Finally, type definitions alone tell me a great deal about the function, but there's still a number of functions which have identical type definitions and terse enough names to leave me unsure which is the one that I seek.

Does a listing like the one I describe exist?

+3  A: 

I used to print out the H98 prelude and memorize it before exams.

http://www.haskell.org/onlinereport/prelude-index.html

Maybe we could have a modern base library cheat sheet though?

Don Stewart
This will be very helpful, thank you. Even though it's not my "ideal" it's actually better than I hoped and will likely get me through this current rough patch. I'm going to leave the question open for now to see if any other suggestions come in. Thanks again.I do think something like my "ideal" listing would benefit the Haskell community, particularly for pedagogy. And since the three elements I suggest are unlikely to change much over the years, maintenance should be minimal. I'm just a little too new to Haskell to spearhead such an effort. Hopefully, it already exists!
Greg
+13  A: 

There is something much better than a cheat-sheet!

Hoogle: Search functions by their type!

Just cabal install hoogle, and:

$ hoogle "[Maybe a] -> [a]"
Data.Maybe catMaybes :: [Maybe a] -> [a]
$ hoogle "(a -> Bool) -> Maybe a -> Bool"
Data.Foldable all :: Foldable t => (a -> Bool) -> t a -> Bool
Data.Foldable any :: Foldable t => (a -> Bool) -> t a -> Bool

To search not just standard functions, but all libraries available from Hackage, use Hayoo (only has web interface)

For tips for using more suitable functions in your code, use hlint:

Error: Use mapMaybe
Found:
  catMaybes . map f
Why not:
  mapMaybe f

Just cabal install hlint

Hoogle comes as command line, web-interface, irc interface, or local "lambdabot" interface.

yairchu
That's simply incredible. I think I was limiting my own search for a solution by thinking too anachronistically. I've yet to try the other interfaces but I just tried the web UI for Hoogle and Hayoo! and that's definitely going to be a huge asset. Thank you!
Greg
+7  A: 

Besides Hoogle, that lets you search for functions by type or name and is quite useful, it seems like the standard GHC library documentation is pretty much exactly in the format you're asking for.

The documentation for each module (like Data.List or Prelude) is on one page and contains all the function/datatypes/... from that module together with their type signature and usually a short description. For reference the docs contain a link to the implementation source and referenced types/... are hyperlinked for quick access. And there is even a global index for searching by function names in all modules, though Hoogle is probably better suited for this.

sth
Indeed, that's helpful as well. Thank you. It really seems like I was making this search for information harder than it needed to be. Hopefully this will help others down the road. I've certainly gained a lot from these suggestions.
Greg