                    -> Peptide                   -- ^ peptide to build spectrum for
                    -> (XCorrSpecThry -> IO b)   -- ^ action to perform
                    -> IO b
-buildThrySpecXCorr _cp (m,n) chrg pep fun =
-    CUDA.allocaBytes bytes $ \spec ->
-    CUDA.memset spec bytes 0 >>= \rv -> case rv of
-      Just e  -> error e
-      Nothing -> CUDA.withArrayLen (bIonLadder pep) $ \n b_ions -> do
-                 CUDA.withArray    (yIonLadder pep) $ \y_ions   -> do
-                 addIons chrg b_ions y_ions spec n len >> do
+buildThrySpecXCorr _cp (m,n) chrg pep action =
+    CUDA.allocaBytesMemset bytes 0     $ \spec     -> do
+    CUDA.withArrayLen (bIonLadder pep) $ \l b_ions -> do
+    CUDA.withArray    (yIonLadder pep) $ \y_ions   -> do
+    addIons chrg b_ions y_ions spec l len >> do
 
-                 fun (XCorrSpecThry (m,n) spec)
+    action (XCorrSpecThry (m,n) spec)
+
     where
       len   = n - m + 1
       bytes = fromIntegral len * fromIntegral (sizeOf (undefined::Int))
 
+
+{# fun unsafe addIons
+    { cIntConv          `Int'             ,
+      withDevicePtr*    `DevicePtr Float' ,
+      withDevicePtr*    `DevicePtr Float' ,
+      withDevicePtr*    `DevicePtr Int'   ,
+      cIntConv          `Int'             ,
+      cIntConv          `Int'             } -> `()' #}
 
 #if 0
 buildThrySpecXCorr :: ConfigParams -> Int -> Int -> Peptide -> IO XCorrSpecThry

--
--------------------------------------------------------------------------------

module IonSeries where

#include "kernels/kernels.h"


import Protein

import C2HS
import Foreign.CUDA (DevicePtr, withDevicePtr)
import qualified Foreign.CUDA as CUDA


