We’re not quite finished with the program that has been the motivator of this chapter. Now for the dictionary filtering. We’ll do this bit by loading a list of words into a hash-like structure and then testing whether a word is present. Here’s the code. I’m sure you could write this code in several brilliant ways, and it won’t advance our understanding of Haskell or functional programming much to examine it in detail, so I’ll be brief.
|||-- import lines should go at the top|
|||import Data.Set(Set, fromDistinctAscList, member)|
|||dict = fromDistinctAscList|
|||$ unsafePerformIO (readFile "fours.txt")|
|||is_valid_word w = member w dict|
The previous code loads a list of words ...