Commits

Luke Plant committed 263b43a

Rewrote buildTree to use foldl'

  • Participants
  • Parent commits f925ceb

Comments (0)

Files changed (1)

File phone2word.hs

 
 import Char (isDigit, toUpper)
 import Control.Monad (guard)
-import Data.List (partition, nub, sort)
+import Data.List (partition, nub, sort, foldl')
 import Maybe (fromJust)
 import System.Environment (getArgs)
 
                      }
 
 buildWordTree :: [B.ByteString] -> WordTree
-buildWordTree words = buildWordTree' words startNode
-    where
-      buildWordTree' [] tree = tree
-      buildWordTree' (w:ws) tree = buildWordTree' ws (addWord w w tree)
-
+buildWordTree words =
+    foldl' (\t w -> addWord w w t) startNode words
 
 addWord :: B.ByteString -- ^ remaining characters
         -> B.ByteString -- ^ whole word