title: How can I solve this datatype problem with only one function,best with pattern matching
body: <p>I'm doing my Haskell Datentyp homework, and have try to solve this problem for a whole day.</p>
  
  <p>The question is like this .</p>
  
  <p>Use this Datentyp and only one function <code>tokenize</code>, other functions in the library are not permitted.</p>
  
  <pre><code>data Token = Text String
             | Placeholder String
               deriving (Eq, Show)
  
  tokenize :: String -&gt; [Token]
  </code></pre>
  
  <p>The brace is the sign of Placeholder</p>
  
  <p>The result should like this:
  when we give input<code>"Hallo {name}, {xyz}."</code></p>
  
  <p>should give <code>[Text "Hallo ", Placeholder "name", Text ", ", Placeholder "xyz", Text "."]</code> out</p>
  
  <hr>
  
  <p>I have tried for a whole day, only Text output or Placehold is OK, but I have several problems:</p>
  
  <ol>
  <li><p>How to handle curly brackets {}</p></li>
  <li><p>How to use pattern match to match "{longtext...}"</p></li>
  <li><p>Because of Datentype <code>[token]</code>,  <code>tokenize (x: xs) = x :[ Text (xs:[])]</code> do not works , so how to deal with it</p></li>
  <li><p>how to combine the comma and all of them together, with only type <code>[token]</code> result function,I have tried ++ and : , but they all report error.</p></li>
  <li><p>According to 4, there is a common question besides this homework: when using Datentype, and type of result doesn't fits type of input,  how to use recursion.</p></li>
  </ol>
  
  <hr>
  
  <p>This is the last edition of my answer, it is still far away</p>
  
  <pre><code>data Token = Text String
             | Placeholder String
               deriving (Eq, Show)
  
  tokenize :: String -&gt; [Token]
  tokenize [] = []
  tokenize ('{':x:xs) = [ Placeholder (x:xs)]
  tokenize (x: xs) = [ Text (x:xs)]
  otherwise = error "TODO: Implementierung vervollstaendigen"
  
  </code></pre>
  
  <p>The result should like this:
  when we give input<code>"Hallo {name}, {xyz}."</code></p>
  
  <p>should give <code>[Text "Hallo ", Placeholder "name", Text ", ", Placeholder "xyz", Text "."]</code> out</p>
  
  <hr>
  
  <p><strong>Suppose all the input without internal bracket and are correctly denoted by curly brackets{}</strong></p>