Skip to Content
Effective Haskell
book

Effective Haskell

by Rebecca Skinner
July 2023
Intermediate to advanced
670 pages
17h 13m
English
Pragmatic Bookshelf
Content preview from Effective Haskell

Memoizing editDistance

We’ve narrowed down our immediate performance problem to recalculating the same edit distances many times. The question now is, what can we do about that? One option is to simply avoid recalculating distances that we’ve already calculated once. If we replace our editDistance function with a version that remembers arguments it’s been called with, and the results that were returned, then we can use the cached values rather than recomputing the distance whenever we encounter a familiar pair of strings. This is a technique called memoization, and it’s common in many different languages and styles of programming.

When we want to memoize a function, Haskell offers us both some benefits and some challenges. The most immediate ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Grokking Functional Programming

Grokking Functional Programming

Michal Plachta
Grokking Algorithms

Grokking Algorithms

Aditya Bhargava
The Rust Programming Language, 2nd Edition

The Rust Programming Language, 2nd Edition

Steve Klabnik, Carol Nichols

Publisher Resources

ISBN: 9798888650400Errata Page