lines/unlines と words/unwords

ghciにて。

Prelude> lines "hoge\nhoge\n\nhoge"                                                                
["hoge","hoge","","hoge"]                                                                           
Prelude> unlines ["hoge","hoge","","hoge"]                                                          
"hoge\nhoge\n\nhoge\n"                                                                             
  • lines は改行文字を取り除く
  • unlines は最後の要素を含め、全て末尾に改行文字をつける
Prelude> words "  a  b     c      d   "
["a","b","c","d"]                                                                                
Prelude> unwords ["a","b","c","d"]                                                               
"a b c d"  
  • words はスペースの個数は関係なく区切る
  • unwords は最後にスペースを付加したりしない