Commits

Luke Plant  committed 47667dd

Specify dictionary file as command line argument

  • Participants
  • Parent commits 7d7b630

Comments (0)

Files changed (1)

File phone2word.hs

 import Control.Monad (guard)
 import Data.List (partition, nub, sort)
 import Maybe (fromJust)
-
+import System.Environment (getArgs)
 
 import qualified Data.ByteString.Char8 as B
 import qualified Data.Map as Map
 -- Main
 --
 
-getWords :: IO [B.ByteString]
-getWords = B.readFile "/usr/share/dict/words" >>= (return . (filter (\x -> B.length x > 1)) . B.lines)
+getWords :: String -> IO [B.ByteString]
+getWords dictFile = B.readFile dictFile >>= (return . (filter (\x -> B.length x > 1)) . B.lines)
 
 countNodes t = 1 + (sum $ map countNodes (nodeSubForest t))
 
 countWords t = length (nodeWords t) + (sum $ map countWords (nodeSubForest t))
 
 main = do
-  ws <- getWords
+  dictFile:_ <- getArgs
+  ws <- getWords dictFile
   let wordTree = buildWordTree ws
   putStr "Words: "
   print (countWords wordTree)