totalLength = B.length digits
- -- The following functions, (makeMap, updateMap) may have trivial
- -- implementations, but they allow us to change the datastructure WordMap
- -- with minimal changes to the rest.
+ -- The following functions may have trivial implementations, but they allow
+ -- us to change the datastructure WordMap with minimal changes to the rest.
makeMap :: WordList -> WordMap
+ -- We can convert straight back to the WordList by removing entries
+ -- with no words, saving work later.
+ makeMap wl = filter (not . null . snd) wl
updateMap :: WordMap -> WordList -> WordMap
updateMap wordMap additional = wordMap ++ additional
- -- get a list of all (position,length) wh
ere there are actually words
+ -- get a list of all (position,length) wh words
findWordPositions :: WordMap -> [(Int,Int)]
- findWordPositions wordMap = nub
[ x | (x, words) <- wordMap, not $ null word s ]
+ findWordPositions wordMap = nub word
- -- get
the entries where there are actually words
+ -- get words
findWordEntries :: WordMap -> WordList
wordMap = filter (not . null . snd) wordMap