Commits

Luke Plant  committed f604add

Cleanup

  • Participants
  • Parent commits 862ca93

Comments (0)

Files changed (1)

File phone2word.hs

 -- Building the tree
 --
 
-startNode = Node { nodeSubForest = Map.empty
+emptyNode = Node { nodeSubForest = Map.empty
                  , nodeWords = []
                  }
 
-newNode :: Char -> WordTree
-newNode digit = Node { nodeSubForest = Map.empty
-                     , nodeWords = []
-                     }
-
 buildWordTree :: [B.ByteString] -> WordTree
 buildWordTree words =
-    foldl' (\t w -> addWord w w t) startNode words
+    foldl' (\t w -> addWord w w t) emptyNode words
 
 addWord :: B.ByteString -- ^ remaining characters
         -> B.ByteString -- ^ whole word
                      let matching = Map.lookup d $ nodeSubForest tree
                          node = case matching of
                                   -- if node does not exist, need to create it
-                                  Nothing -> newNode d
+                                  Nothing -> emptyNode
                                   Just n -> n
                          node' = addWord cs word node
                      in tree { nodeSubForest = Map.insert d node' $ nodeSubForest tree }