Haskell: Inserting every line from a file into a list

前端 未结 2 1197
囚心锁ツ
囚心锁ツ 2020-12-31 10:22

I\'m currently working on project with Haskell, and have found myself some trouble. I\'m supposed to read and insert into a list each line in a \"dictionary.txt\" file, but

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-31 11:05

    Unless this is for homework or something, there's no reason to use so much effort. Reuse is lazy!

    getLines = liftM lines . readFile
    
    main = do
        list <- getLines "dictionary.txt"
        mapM_ putStrLn list
    

    But as you seem to still be learning Haskell, it is important for you to understand what CesarB has written.

提交回复
热议问题