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 catMaybes catMaybes :: [Maybe a] -> [a] -- Defined in ‘Data.Maybe’ >
:info
shows both the type of thecatMaybes
and where it is defined.
在OCaml中,可以使用哪些网站/工具按名称或类型搜索函数?
例如,我正在阅读Real World OCaml。我遇到了一些代码,使用
|>
函数。我想知道是否有一个函数<|
以相反的方式组合。然而,我不知道任何搜索名为<|
的函数的方法。此外,我不知道如何找出|>
定义在哪里。
根据上面的链接代码,我猜想|>
要么在Pervasives中,要么在Jane Street的Core中的某个地方,但是有一个工具能给出确切的位置就好了。