diff options
Diffstat (limited to 'lib/Data/Packed/Internal/Vector.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Vector.hs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs index fc8a6be..1b572a5 100644 --- a/lib/Data/Packed/Internal/Vector.hs +++ b/lib/Data/Packed/Internal/Vector.hs | |||
@@ -18,6 +18,7 @@ module Data.Packed.Internal.Vector where | |||
18 | 18 | ||
19 | import Data.Packed.Internal.Common | 19 | import Data.Packed.Internal.Common |
20 | import Foreign | 20 | import Foreign |
21 | import Foreign.C.Types(CInt) | ||
21 | import Complex | 22 | import Complex |
22 | import Control.Monad(when) | 23 | import Control.Monad(when) |
23 | 24 | ||
@@ -36,6 +37,8 @@ data Vector t = | |||
36 | , fptr :: {-# UNPACK #-} !(ForeignPtr t) -- ^ foreign pointer to the memory block | 37 | , fptr :: {-# UNPACK #-} !(ForeignPtr t) -- ^ foreign pointer to the memory block |
37 | } | 38 | } |
38 | 39 | ||
40 | -- C-Haskell vector adapter | ||
41 | vec :: Adapt (CInt -> Ptr t -> r) (Vector t) r | ||
39 | vec = withVector | 42 | vec = withVector |
40 | 43 | ||
41 | withVector (V n fp) f = withForeignPtr fp $ \p -> do | 44 | withVector (V n fp) f = withForeignPtr fp $ \p -> do |
@@ -43,7 +46,7 @@ withVector (V n fp) f = withForeignPtr fp $ \p -> do | |||
43 | g (fi n) p | 46 | g (fi n) p |
44 | f v | 47 | f v |
45 | 48 | ||
46 | -- | allocates memory for a new vector | 49 | -- allocates memory for a new vector |
47 | createVector :: Storable a => Int -> IO (Vector a) | 50 | createVector :: Storable a => Int -> IO (Vector a) |
48 | createVector n = do | 51 | createVector n = do |
49 | when (n <= 0) $ error ("trying to createVector of dim "++show n) | 52 | when (n <= 0) $ error ("trying to createVector of dim "++show n) |