title: (RGBData on Haskell) Pattern match failure
body: <p>im new using Haskell, im doing a proyect and i got some doubts with data types.</p>
  
  <p>im working with PBM files and im using this data types</p>
  
  <pre><code>data RGBdata= RGB Int Int Int
  data PBMfile= PBM Int Int [[RGBdata]]
  </code></pre>
  
  <p>also this code that the teacher gave to us</p>
  
  <pre><code>instance Show RGBdata where
  show (RGB r g b)=(show r)++" "++(show g)++" "++(show b)
  instance Show PBMfile where
  show (PBM width height l)= "P3\n"++(show width)++" "++(show height)++"\n255\n"++(foldr    (++) "" (map myshow l))
  myshow [] = "\n"
  myshow (h:t) = (show h)++" "++(myshow t)
  cargarPBM name = readFile name &gt;&gt;= return . rLines . lines 
  rLines (_:x:_:xs)= (\[a,b] -&gt; (PBM (read a) (read b) (rLines' (read a) (concat $map     words xs)))) $ words x
  rLines' _ [] = []
  rLines' a x = (rLine (take (a*3) x): rLines' a (drop (a*3) x))
  rLine []= []
  rLine (r:g:b:xs)= ((RGB (read r) (read g) (read b)):rLine xs)
  aplicar funcion origen destino= cargarPBM origen &gt;&gt;= writeFile destino . show . funcion
  </code></pre>
  
  <p>Then i need to do some functions with the PBM files, like transform it to negative, rotate it, etc..
  im starting making the PBM negative, to transform to negative is (RGB 255-R 255-G 255-B)</p>
  
  <p>i did a function to make a PBMfile negative! here is the code i did..</p>
  
  <pre><code>negativo :: PBMfile -&gt; PBMfile
  negativo (PBM i j mtx) = (PBM i j (aplicar_negativo 0 (i*j) mtx)) 
  
  aplicar_negativo :: Int -&gt; Int -&gt; [[RGBdata]] -&gt; [[RGBdata]]
  aplicar_negativo a n (x:xs) | ((a+2)==n) = (aplicar_negativo2 [x])++(aplicar_negativo2 xs)
                          | otherwise = (aplicar_negativo2 [x])++(aplicar_negativo (a+1) n xs)
  
  aplicar_negativo2 :: [[RGBdata]] -&gt; [[RGBdata]]
  aplicar_negativo2 [[RGB x y z]] = ([[RGB (255-x) (255-y) (255-z)]])
  </code></pre>
  
  <p><strong>this 3 functions just change all rgbdatas to 255-r, 255-g and 255-b.. 
  ie if i have my list of lists [[RGB 100 200 100],[RGB 50 55 50]]
  the result is: [[RGB 155 55 155],[RGB 205, 200, 205]]</strong></p>
  
  <p><strong>And here is the error that i get when i apply the function negativo over a image:</strong></p>
  
  <pre><code>Program error: pattern match failure: aplicar_negativo2 [[RGB (read (_SEL (,) 
  ("6" ++ _SEL (,) ("5" ++ _SEL (,) ([],[]) 1,[]) 1,[]) 1)) (read (_SEL (,) ("1"
  ++ _SEL (,) ("2" ++ _SEL (,) ("6" ++ _SEL (,) ([],[]) 1,[]) 1,[]) 1,[]) 1)) 
  (read (_SEL (,) ("7" ++ _SEL (,) ("1" ++ _SEL (,) ([],[]) 1,[]) 1,[]) 1)),RGB 
  (read (_SEL (,) ("5" ++ _SEL (,) ("2" ++ _SEL (,) ([],[]) 1,[]) 1,[]) 1)) (read
  (_SEL (,) ("1" ++ _SEL (,) ("1" ++ _SEL (,) ("2" ++ _SEL (,) ([],[]) 1,[]) 1,[])
  1,[]) 1)) (read (_SEL (,) (words_v858 (break isSpace "5" ++ _SEL (,) (span_v848 
  (span (not . primEqChar '\n') (_hreader {handle}))) 1)) 1))] ++ rLine (take 
  (700 - 1) (words (_SEL (,) (words_v858 (break isSpace "5" ++ _SEL (,) (span_v848 
  (span (not . primEqChar '\n') (_hreader {handle}))) 1)) 2) ++ foldr (++) [] 
  (map_v810 words (lines_v853 (_SEL (,) ("5" ++ _SEL (,) (span_v848 (span (not .
  primEqChar '\n') (_hreader {handle}))) 1,_SEL (,) (span_v848 (span (not . 
  primEqChar '\n') (_hreader {handle}))) 2) 2)))))]
  </code></pre>
  
  <p><strong>Excuse me for my bad english, Thanks!</strong></p>