ithProblem :: [(Double, V.Vector Double)] -> (Ptr C'svm_problem -> IO b) -> IO b
withProblem v op = -- Well. This turned out super ugly. Possibly even wrong.
                   V.unsafeWith xs $ \ptr_xs ->
                   V.unsafeWith y  $ \ptr_y -> 
                    let optrs = offsetPtrs ptr_xs
                    in V.unsafeWith optrs $ \ptr_offsets ->
                        with (C'svm_problem (fromIntegral dim) ptr_y ptr_offsets) op
    where 
        dim = length v
        lengths = map (V.length . snd) v
        offsetPtrs addr = V.fromList 
                          [addr `plusPtr` (idx * sizeOf (xs ! 0))
                          | idx <- scanl (+) 0 lengths]
        y   = V.fromList . map (realToFrac . fst) $ v
        xs  = V.concat . map (extractSvmNode.snd) $ v
        extractSvmNode x = convertDense $ V.generate (V.length x) (x !)

ne
withProblem :: [(Double, V.Vector Double)] -> (Ptr C'svm_problem -> IO b) -> IO b
withProblem v op = -- Well. This turned out super ugly. Possibly even wrong.
                   V.unsafeWith xs $ \ptr_xs ->
                   V.unsafeWith y  $ \ptr_y -> 
                    let optrs = offsetPtrs ptr_xs
                    in V.unsafeWith optrs $ \ptr_offsets ->
                        with (C'svm_problem (fromIntegral dim) ptr_y ptr_offsets) op
    where 
        dim = length v
        lengths = map (V.length . snd) v
        offsetPtrs addr = V.fromList 
                          [addr `plusPtr` (idx * sizeOf (xs ! 0))
                          | idx <- scanl (+) 0 lengths]
        y   = V.fromList . map (realToFrac . fst) $ v
        xs  = V.concat . map (extractSvmNode.snd) $ v
        extractSvmNode x = convertDense $ V.generate (V.length x) (x !)
withProblem v op = -- Well. This turned out super ugly. Possibly even wrong.
                   V.unsafeWith xs $ \ptr_xs ->
                   V.unsafeWith y  $ \ptr_y -> 
                    let optrs = offsetPtrs ptr_xs
                    in V.unsafeWith optrs $ \ptr_offsets ->
                        with (C'svm_problem (fromIntegral dim) ptr_y ptr_offsets) op
    where 
        dim = length v
        lengths = map (V.length . snd) v
        offsetPtrs addr = V.fromList 
                          [addr `plusPtr` (idx * sizeOf (xs ! 0))
                          | idx <- scanl (+) 0 lengths]
        y   = V.fromList . map (realToFrac . fst) $ v
        xs  = V.concat . map (extractSvmNode.snd) $ v
        extractSvmNode x = convertDense $ V.generate (V.length x) (x !)