In Haskell, there are two main ways to look up information on functions.
Sites like Hoogle and Stackage. These sites provide two main types of searching:
Searching for the name of a function. For example, here is a search on Hoogle for a function called
catMaybes
.This search returns the type of the
catMaybes
function, as well as the package and module it is defined in.The major use-case for this type of search is when you see a function used somewhere and you want to know its type and what package it is defined in.
Searching for the type of a function. For example, here is a search on Hoogle for a function of type
[Maybe a] -> [a]
.This search returns multiple functions that have a similar type, the first of which is
catMaybes
. It also returns the package and modulecatMaybes
is defined in.The major use-case for this type of search occurs when you are writing code. You know the type of the function you need, and you're wondering if it is already defined somewhere. For example, you have a list of
Maybe
s, and you want to return a list with all theNothing
s removed. You know the function is going to have the type[Maybe a] -> [a]
.
Directly from
ghci
. Inghci
, it is easy to get information about a function with the:info
command, as long as the function is already in your environment.For example, here is a
ghci
session showing how to get info about thecatMaybes
function. Note how you must import theData.Maybes
module first:> import Data.Maybe> :info catMaybescatMaybes :: [Maybe a] -> [a] -- Defined in ‘Data.Maybe’>
:info
shows both the type of thecatMaybes
and where it is defined.
In OCaml, what sites/tools can be used to search for functions by name or type?
For example, I'm reading through Real World OCaml. I came across some code using the |>
function. I wondered if there was a function <|
for composing the opposite way. However, I don't know of any way of searching for a function called <|
. Also, I don't know of any way of figuring out where |>
is defined.
Based on the linked code above, I guess the |>
would either have to be in Pervasives or somewhere in Jane Street's Core, but it would be nice to have a tool that gave the exact location.