title: Haskell: How To Fix Error With "add An Instance Declaration For (Unbox A)" When Using Unboxed Vectors?
body: <p>I have written some code in which a small part of the code takes a large one dimensional Unboxed.Vector and returns them as a Vector (Vector a). </p>
  
  <p>A part of the code is giving an error. Here is a sample piece of code that is similar to the actual code and gives the same error.</p>
  
  <pre><code>import Data.Vector.Unboxed as D
  
  
  xs = [0,1,2,3,4,5,6,7,8,9,10,11]
  rows = 3
  cols = 4
  
  sb = D.fromList xs
  
  takeRows::Int -&gt; Int -&gt; Vector Int -&gt; Vector (Vector Int)
  takeRows rows cols x0 = D.map (\x -&gt; D.slice x (fromIntegral cols) x0) starts
                          where
                           starts = D.enumFromStepN 0 cols rows
  
  -- takeRowsList::Int -&gt; Int -&gt; Vector Int -&gt; [Vector Int]                                                         
  -- takeRowsList rows cols x0 = Prelude.map (\x -&gt; D.slice x (fromIntegral cols) x0) starts                        
  --  where                                                                                  
  --  starts = D.toList . D.enumFromStepN 0 cols $ rows                                    
  </code></pre>
  
  <p>the error is </p>
  
  <pre><code>No instance for (Unbox (Vector Int))
    arising from a use of `D.map'
  Possible fix: add an instance declaration for (Unbox (Vector Int))
  In the expression:
    D.map (\ x -&gt; slice x (fromIntegral cols) x0) starts
  In an equation for `takeRows':
      takeRows rows cols x0
        = D.map (\ x -&gt; slice x (fromIntegral cols) x0) starts
        where
            starts = enumFromStepN 0 cols rows
  </code></pre>
  
  <p>I have written a similar function takeRowsList, which makes the outer Vector as a List and this doesn't suffer from the same problem. I've also included it above but commented it out, to demonstrate my problem. </p>
  
  <p>I understand that some functions need type definitions, when, I use them with Unboxed Vectors. But in this case I am stumped as to where to put a type definition. I've tried pretty much type defining everything and I keep getting the above error.</p>
  
  <p>Thanks in advance for your help.</p>