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 ...
Get Functional Programming: A PragPub Anthology now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.