OK, let’s plug the word-chain code into the preceding and see what happens; for example, let’s define the following and run word_chain "lead" "gold".
|||word_chain a b = breadth_first_search (\w -> w == b) one_step a|
You should see the word “gold” popping out every few seconds, which corresponds to each successful path being found. (There might be a short delay while the dictionary is loaded into memory on the first run.)
Oh. This confirms that paths exist, but we really want to know the intermediate steps. The way to get those is to change the state type from a String to something that keeps track of where it’s been—in other words, a list of previous words. The following code lightly wraps up the basic code to maintain this ...