user2879704
user2879704

Reputation:

Function names with symbol characters makes Googling difficult

In Haskell, many function names contain only symbol characters. Like $$, >>=, >>, :, ->, =>, =~.

Since I am new to Haskell, I am finding it difficult to search their meanings in Google. For example, to understand what -> means in Haskell, I need to use the search string hyphen followed by greater than which is not the best approach, as per me.

Is there a place that I could search for functions with symbols only?

Upvotes: 11

Views: 874

Answers (1)

CR Drost
CR Drost

Reputation: 9817

Yes, this is a known bug with Google. You might consider a better search engine like Hoogle.

In general you need to look up the documentation for the actual function. To do this, you need to know what module it's defined in. The easiest way to determine this is to load up your source file in GHCi (so that you have all of its imports etc.) and then ask for the operator's :info thusly:

Prelude> :info (>>=)
class Monad (m :: * -> *) where
  (>>=) :: m a -> (a -> m b) -> m b
  ...
    -- Defined in ‘GHC.Base’
infixl 1 >>=
Prelude> 

If the type signature is not enough, then this also tells you that you need to google the GHC.Base module, and the Monad typeclass. By itself that's pretty googleable, but if that typeclass keyword weren't there, what you would do is to google GHC.Base, the first result leading to the base package overview page. Once you are there1 then you look for a little link labeled [Index] beneath the module listing (GHC.Base has a huge module listing so in this case it's easier to miss).

Clicking that link takes you to an index of all the public symbols in that package; you can click the > character to find all operators beginning with a greater than sign. You will then have three links of modules which export that function; click on one and Ctrl-F to find the following documentation:

(>>=) :: forall a b. m a -> (a -> m b) -> m b  | infixl 1 | Source
    Sequentially compose two actions, passing any value produced by the first 
    as an argument to the second.

Again, Hoogle does all of this rigamarole for you and has some other nifty features like searching-by-type-signature.

For things like <-, ->, and => which are not functions, you will just have to know the language. The meaning of <- ("from") is from "do-notation", which you can Google; the meaning of -> ("to") varies depending on whether it appears in lambda-notation (like \a b -> b), case-expressions, or the type signature of a function (where a -> b -> c means "a function which takes an a and returns a function which takes a b and returns some c". The meaning of => is from "constraints" or "type classes" in Haskell.

Other than ->, you can sometimes see operators appearing in type signatures, too. These should be searchable by the above procedure.

  1. This is assuming a stable API for the package. If the API has changed you will need to look up with ghc -v which package version the file is using, then click on that version.

Upvotes: 23

Related Questions