title: Haskell split lines into list including empty lines
body: <p>So have this</p>
  
  <pre><code>type DocName = FilePath
  type Line = (Int,String)
  type Document = [Line]
  
  splitLines :: String -&gt; Document
  splitLines [] = []
  splitLines str = zip [0..(length listStr)] listStr
                                      where 
                                          listStr = [getLine] ++ map snd (splitLines getRest)
                                          getLine = (takeWhile (/='\n') str)
                                          getRest =  (dropWhile (=='\n') (dropWhile (/='\n') str))
  </code></pre>
  
  <p>works ok except i guess i need empty lines as well.</p>
  
  <pre><code>splitLines "test\nthis\nstring\n" should be
  [(0,"test"),(1,"this"),(2,"string"),(3,"")]
  </code></pre>
  
  <p>Not exactly sure how i could do this. Any ideas?
  Do i need to rewrite it with something else?</p>
  
  <p>Should i use a high order function like foldr?
  Thanks.</p>
  
  <p>Figured it out finally thanks.</p>
  
  <pre><code>splitLines :: String -&gt; Document
  splitLines "" = [(0,"")]
  splitLines str = zip [0..(length listStr)] listStr
                                      where 
                                          listStr = [getLine] ++ map snd (splitLines getRest)
                                          getLine = takeWhile (/='\n') str
                                          getRest = tail (dropWhile (/='\n') str)
  </code></pre>