hoogle-4.2.43: Haskell API Search

Safe Haskell | None
Language | Haskell98

Hoogle

Contents

- Utility types
- Database
- Query
- Score
- Search

Description

The Hoogle API. To perform a search you call `search` with a `Database` (obtained by `loadDatabase`) and a `Query` (obtained by `parseQuery`).

Synopsis

- data TagStr
  - = Str String
  - | Tags [TagStr]
  - | TagBold TagStr
  - | TagEmph TagStr
  - | TagLink String TagStr
  - | TagColor Int TagStr
- showTagText :: TagStr -> String
- showTagANSI :: TagStr -> String
- showTagHTML :: TagStr -> String
- showTagHTMLWith :: (TagStr -> Maybe String) -> TagStr -> String
- data ParseError = ParseError {
  - lineNo :: Int
  - columnNo :: Int
  - errorMessage :: String
  - parseInput :: TagStr
  }
- type URL = String
- data Language = Haskell
- data Database
- loadDatabase :: FilePath -> IO Database
- saveDatabase :: FilePath -> Database -> IO ()
- createDatabase :: HackageURL -> Language -> [Database] -> String -> FilePath -> IO [ParseError]
- mergeDatabase :: [FilePath] -> FilePath -> IO ()
- showDatabase :: Database -> Maybe [String] -> String
- defaultDatabaseLocation :: IO FilePath
- data Query
- parseQuery :: Language -> String -> Either ParseError Query
- renderQuery :: Query -> TagStr
- queryDatabases :: Query -> [String]
- queryPackages :: Query -> [(Bool, String)]
- querySetPackage :: Maybe Bool -> String -> Query -> Query
- data Score
- scoring :: [(Score, Score)] -> IO String
- data Result = Result {
  - locations :: [(URL, [(URL, String)])]
  - self :: TagStr
  - docs :: TagStr
  }
- search :: Database -> Query -> [(Score, Result)]
- suggestions :: Database -> Query -> Maybe TagStr
- completions :: Database -> String -> [String]
- queryExact :: Maybe ItemKind -> Query -> Query
- data ItemKind
  - = PackageItem
  - | ModuleItem
  - | FunctionItem
  - | DataCtorItem
  - | TypeCtorItem
  - | TypeSynonymItem
  - | ClassItem
  - | InstanceItem
  - | UnclassifiedItem

# Utility types

data TagStr Source

Constructors

Str String | Plain text.
Tags [TagStr] | A list of tags one after another.
TagBold TagStr | Bold text.
TagEmph TagStr | Underlined/italic text.
TagLink String TagStr | A hyperlink to a URL.
TagColor Int TagStr | Colored text. Index into a 0-based palette. Text without any `TagColor` should be black.

Instances

Eq TagStr Source |
Data TagStr Source |
Ord TagStr Source |
Show TagStr Source |
Monoid TagStr Source |
Binary TagStr Source |
NFData TagStr Source |
Uniplate TagStr Source |

showTagText :: TagStr -> String Source

Show a `TagStr` as a string, without any formatting.

showTagANSI :: TagStr -> String Source

Show a `TagStr` on a console with ANSI escape sequences.

showTagHTML :: TagStr -> String Source

Show a `TagStr` as HTML, using CSS classes for color styling.

showTagHTMLWith :: (TagStr -> Maybe String) -> TagStr -> String Source

Show TagStr with an override for specific tags.

data ParseError Source

Data type representing a parse error. All indecies are 1-based.

Constructors

ParseError |

Fields

lineNo :: Int

  Line number on which the error occured, 1 for the first line of a file.

columnNo :: Int

  Column number on which the error occured, 1 for the first character of a line.

errorMessage :: String

  Error message caused by the parse error.

parseInput :: TagStr

  Input string which caused the error - sometimes with a `TagEmph` to indicate which part was incorrect.

Instances

Eq ParseError Source |
Data ParseError Source |
Ord ParseError Source |
Show ParseError Source |

type URL = String Source

A URL, or internet address. These addresses will usually start with either `http://` or `file://`.

data Language Source

The languages supported by Hoogle.

Constructors

Haskell | The Haskell language (http://haskell.org/), along with many GHC specific extensions.

Instances

Bounded Language Source |
Enum Language Source |
Eq Language Source |
Data Language Source |
Ord Language Source |
Read Language Source |
Show Language Source |

# Database

data Database Source

A Hoogle database, containing a set of functions/items which can be searched. The `Database` type is used for a variety of purposes:

Creation
  A database is created by merging existing databases with the `Monoid` instance and `mappend`, or by creating a new `Database` from an input file with `createDatabase`.
Serialization
  A database is saved to disk with `saveDatabase` and loaded from disk with `loadDatabase`.
Searching
  A database is searched using `search`.

Instances

Show Database Source |
Monoid Database Source |
NFData Database Source |

loadDatabase :: FilePath -> IO Database Source

Load a database from a file. If the database was not saved with the same version of Hoogle, it will probably throw an error.

saveDatabase :: FilePath -> Database -> IO () Source

Save a database to a file.

createDatabase Source

Arguments

:: HackageURL |
-> Language | Which format the input definition is in.
-> [Database] | A list of databases which contain definitions this input definition relies upon (e.g. types, aliases, instances).
-> String | The input definitions, usually with one definition per line, in a format specified by the `Language`.
-> FilePath | Output file
-> IO [ParseError] | A list of any parse errors present in the input definition that were skipped.

Create a database from an input definition. Source files for Hoogle databases are usually stored in UTF8 format, and should be read using `hSetEncoding` and `utf8`.

mergeDatabase :: [FilePath] -> FilePath -> IO () Source

showDatabase :: Database -> Maybe [String] -> String Source

Show debugging information on some parts of the database. If the second argument is `Nothing` the whole database will be shown. Otherwise, the listed parts will be shown.

defaultDatabaseLocation :: IO FilePath Source

# Query

data Query Source

A query, representing a user input.

Instances

Eq Query Source |
Data Query Source |
Show Query Source |
Monoid Query Source |

parseQuery :: Language -> String -> Either ParseError Query Source

Parse a query for a given language, returning either a parse error, or a query.

renderQuery :: Query -> TagStr Source

Render a query, in particular using `TagColor` for any type signature argument positions.

queryDatabases :: Query -> [String] Source

Given a query, return the list of packages that should be searched. Each package will be the name of a database, without any file path or extension included.

queryPackages :: Query -> [(Bool, String)] Source

Return those packages which are explicitly excluded (paired with `False`) or included (paired with `True`) in the query.

querySetPackage :: Maybe Bool -> String -> Query -> Query Source

Set the state of a package within a query. `Nothing` means delete the package, `Just` `True` for add it, and `Just` `False` for remove it.

# Score

data Score Source

A score, representing how close a match is. Lower scores are better.

Instances

Eq Score Source |
Ord Score Source |
Show Score Source |
Monoid Score Source |

scoring :: [(Score, Score)] -> IO String Source

Given a set of scores, where the first is lower than the second, returns details for how to rank scores. This function is in the `IO` monad since it may require randomness, and it may output status messages while solving, particularly if in Verbose mode.

# Search

data Result Source

Constructors

Result |

Fields

locations :: [(URL, [(URL, String)])]
self :: TagStr

  Rendered view for the entry, including namekeywordstype as appropriate, colors matching `renderQuery`

docs :: TagStr

  Documentation for the entry

Instances

Eq Result Source |
Show Result Source |

search :: Database -> Query -> [(Score, Result)] Source

Perform a search. The results are returned lazily.

suggestions :: Database -> Query -> Maybe TagStr Source

Given a query and a database optionally give a list of what the user might have meant.

completions :: Database -> String -> [String] Source

Given a query string and a database return a list of the possible completions for the search.

queryExact :: Maybe ItemKind -> Query -> Query Source

Given a query, set whether it is an exact query.

data ItemKind Source

Constructors

PackageItem |
ModuleItem |
FunctionItem |
DataCtorItem |
TypeCtorItem |
TypeSynonymItem |
ClassItem |
InstanceItem |
UnclassifiedItem |

Instances

Enum ItemKind Source |
Eq ItemKind Source |
Data ItemKind Source |
Show ItemKind Source |
NFData ItemKind Source |