Haskell ---在列表上迭代拆分函数

时间:2015-03-30 02:16:52

标签: list haskell dictionary printing split

getLines = liftM lines . readFile

main = do
    argv <- getArgs
    name <- getProgName
    if not (null argv)
    then do
           let file = head argv 
           list <- getLines file
           let olist = mergesort (<=) list
           let splitter = map (split ",")  olist
           loop splitter 
    else hPutStr stderr $ "usage: " ++ name ++ " filename"

loop a = do 
    line <- getLine
    case line of
     "help"  -> putStrLn "print - prints list in alphabetical order\n\
                \quit  - exits program"
     "print" -> do putStrLn "[print]"
                   mapM_ putStrLn a
                   putStr "\n"
     "quit"  -> do putStrLn "[quit]" 
                   exitSuccess
     _       -> putStrLn "invalid command" 
    loop a

我试图拆分每个都有逗号的行列表,除了我在循环拆分器中出错。我认为这是因为我的循环函数中的mapM_ putStrLn无法理解新列表。在我使用拆分器功能之前,我的程序会打印出从文本文件中获取的整个列表,没有任何问题。如何打印出以逗号分隔的新单词列表?

0 个答案:

没有答案