title: parse a cv file
body: <p><br />
  My code doesn't compile. It seems that the problem lies in the main function with lookup.<br />
  I am trying to parse an file that look like this :<br /></p>
  
  <p>auiauiaui@tsrntsr.epep 584756 "srtrtte"<br />
  jepeto@pinokio.disney 464456454 "cendrillon"<br /></p>
  
  <p>If you name the file lol and the code prog then calling prog lol 1 2 will return 464456454.<br /></p>
  
  <p>EDIT :</p>
  
  <p>Thanks,</p>
  
  <p>See I have a file named filetest like this :<br />
  field1-1 field1-2 field1-3<br />
  field2-1 field2-2 field2-3<br />
  field3-1 field3-2 field3-3<br />
  field4-1 field4-2 field4-3<br />
  field5-1 field5-2 field5-3<br /></p>
  
  <p>Now my piece of code is suppose to grab a field given the line and the rank.<br />
  mycode filetest give me the number of lines in the file (so that i can use a script for each lines).</p>
  
  <p>Here some example :<br />
  mycode filetest 1 2 -> field1-2<br />
  mycode filetest 2 2 -> field2-2<br />
  mycode filetest 3 4 -> field3-4<br />
  mycode filetest 3 2 -> field3-2<br />
  mycode filetest 2 5 -> field2-5<br />
  mycode filetest 1 4 -> field1-4<br /></p>
  
  <p>Now each field contain a String.<br /></p>
  
  <p>What i do is grab the file as a string then grab the line wanted (with lines) and then grab the field (with words).<br /></p>
  
  <p>I corrected my errors (thanks to the #haskell and #haskell-fr channel and you). But my code doesn't work as expected at all.<br /></p>
  
  <p>Any help shall be appreciated. Here is the néw code :<br /></p>
  
  <pre><code>import System.Environment
  import System.IO
  
  fieldArg :: Int -&gt; [String] -&gt; String
  fieldArg x a = if length a &gt; 2
                  then if x &lt; 4 then a !! x else "field number is too high"
                  else "field number is too low"
  
  lineArg :: Int -&gt; [String] -&gt; String
  lineArg x a
      | x &gt; length a = "line number is too big"
      | x &lt; 1        = "line number is too low"
      | otherwise    = a !! x
  
  extrcta :: Int -&gt; Int -&gt; String -&gt; String
  extrcta x n = fieldArg x . words . lineArg n . lines
  
  
  argList :: String -&gt; [((Int, String), String -&gt; String)]
  argList n = let n1 = read n
              in [((1, n), extrcta 1 n1)
                 ,((2, n), extrcta 2 n1)
                 ,((3, n), extrcta 3 n1)
                 ]
  
  
  main :: IO ()
  main = do
          args &lt;- getArgs
          case args of
                     (path: opt1: opt2: _) -&gt; case (read opt1, opt2) `lookup` argList opt2 of
                                                                                         Nothing -&gt; putStrLn $ "Wrong argument " ++ opt1 ++ " or " ++ opt2
                                                                                         Just act -&gt; withFile path ReadMode (\handle -&gt; do
                                                                                                                                         contents &lt;- hGetContents handle
                                                                                                                                         putStrLn $ act contents)
                     (path: _) -&gt; withFile path ReadMode (\handle -&gt; do
                                                                      contents &lt;- hGetContents handle
                                                                      (print (length $ lines contents)))
                     _ -&gt; putStrLn "Wrong number of argument"
  </code></pre>
  
  <p>EDIT2 : Thanks</p>