title: Reading string data into haskell data type?
body: <p>Short-and-sweet, I have a text file that looks like this:</p>
  
  <pre><code>ID1|ID2|DATE|SUM
  0|0|20/03/2014|100.00
  0|1|20/04/2014|99.00
  </code></pre>
  
  <p>I have a custom data type that looks like this:</p>
  
  <pre><code>data DBData = DBData { id1   :: Int
                       , id2   :: Int
                       , date  :: String
                       , sum   :: Int
                       } deriving (Eq, Read, Show)
  </code></pre>
  
  <p>How do I get this into that?</p>
  
  <p>What I have been toying with so far is using something like this:</p>
  
  <pre><code>parseRow :: [String] -&gt; DBData 
  parseRow = let (id1:id2:date:sum) = (splitWhen (=='|')) s
                  i = read id1
               in DBData {id1 = i}
  </code></pre>
  
  <p>But I can't seem to get the syntax right ... </p>
  
  <p>related to my other post:
  <a href="https://stackoverflow.com/questions/25477554/using-splitwhen-to-split-string-by-delimiter-and-trying-to-figure-out-how-to-sto">https://stackoverflow.com/questions/25477554/using-splitwhen-to-split-string-by-delimiter-and-trying-to-figure-out-how-to-sto</a></p>