title: Haskell - Splitting a string by delimiter
body: <p>I am trying to write a program in Haskell to split a string by delimiter.</p>
  
  <p>And I have studied different examples provided by other users. An example would the the code that is posted below.</p>
  
  <pre><code>split :: String -&gt; [String]
  split [] = [""]
  split (c:cs)
     | c == ','  = "" : rest
     | otherwise = (c : head rest) : tail rest
   where
     rest = split cs
  </code></pre>
  
  <p>Sample Input: <code>"1,2,3"</code>.
  Sample Output: <code>["1","2","3"]</code>.</p>
  
  <p>I have been trying to modify the code so that the output would be something like <code>["1", "," , "2", "," , "3"]</code> which includes the delimiter in the output as well , but I just cannot succeed.</p>
  
  <p>For example, I changed the line:</p>
  
  <pre><code>   | c == ','  = "" : rest
  </code></pre>
  
  <p>into:</p>
  
  <pre><code>   | c == ','  = "," : rest
  </code></pre>
  
  <p>But the result becomes <code>["1,","2,","3"]</code>.</p>
  
  <p>What is the problem and in which part I have had a misunderstanding?</p>