O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating Candidates

Let’s see, we’re generating and filtering, right? So let’s consider the operation that generates potential words for later filtering. Type-wise, we want generate_candidates :: String -> [String], so that from a given word we get all possible next steps.

It’s always good to start with some concrete examples, especially if the operation doesn’t seem obvious.

From generate_candidates "", we expect no candidates, since there’s no way to change a single character in an empty string.

From generate_candidates "a", we expect ["b", "c", ... "z"], because we change the character to every other character except "a".

From generate_candidates "ba", we expect ["aa", "ca", "da", ... "za", "bb", "bc", ... "bz" ], which is the list ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required