Commits

Luke Plant  committed 8dd1afe

Cleaned up some code to do less work.

  • Participants
  • Parent commits dc7d541

Comments (0)

Files changed (1)

File phone2word.hs

 
      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
-     makeMap = id
+     -- 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) where there are actually words
+     -- get a list of all (position,length) which have words
      findWordPositions :: WordMap -> [(Int,Int)]
-     findWordPositions wordMap = nub [ x | (x, words) <- wordMap, not $ null words ]
+     findWordPositions wordMap = nub $ map fst $ wordMap
 
-     -- get the entries where there are actually words
+     -- get a list of all entries which have words
      findWordEntries :: WordMap -> WordList
-     findWordEntries wordMap = filter (not . null . snd) wordMap
+     findWordEntries = id
 
 
 --