liveBook · Manning

Hash map

As explained in Learn Haskell by Example

A hash map is a key-value data structure that uses a hash function to support fast average-case lookup, insertion, and deletion.

A hash map provides fast access for key-value lookups. In the word ladder solver, it replaces a slower associative-map implementation so large dictionaries can be processed. section 6.3.2

Using a hash map in the Haskell project involves:

  • Add unordered-containers and hashable to package.yml. section 6.3.2
  • Replace Data.AssocMap with Data.HashMap.Lazy and update related map types. section 6.3.2
  • Require Hashable a when map keys use the type variable a. section 6.3.2

Scaling the word ladder solver

The solver initially handles a 200-word dictionary but takes too long with 58,110 words. Substituting HashMap makes the large dictionary workable; profiling then shows candidate computation and file reading as larger costs than map lookup. section 6.3 section 6.3.2

dependencies:
- base >= 4.7 && < 5
- unordered-containers
- hashable

Dependency configuration for enabling unordered-containers and hashable in the project. section 6.3.2

How Learn Haskell by Example covers it

How deep it goes
Explains library substitution, dependency setup, key constraints, and profiling outcomes, but does not build the hash-map internals.
Examples
Demonstrates replacement in a Haskell word ladder solver using small and large dictionary files.
What it assumes
Assumes familiarity with the existing associative-map functions while teaching dependency installation and Hashable key requirements.
What you can do after
Operate/configure it through Data.HashMap.Lazy, package dependencies, and Hashable constraints to scale dictionary lookup.
How it connects
Connects hash maps with associative maps, Hashable, graph search, permutation maps, profiling, and word ladder solving.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.