summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Vector.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Internal/Vector.hs')
-rw-r--r--lib/Data/Packed/Internal/Vector.hs5
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
19import Data.Packed.Internal.Common 19import Data.Packed.Internal.Common
20import Foreign 20import Foreign
21import Foreign.C.Types(CInt)
21import Complex 22import Complex
22import Control.Monad(when) 23import 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
41vec :: Adapt (CInt -> Ptr t -> r) (Vector t) r
39vec = withVector 42vec = withVector
40 43
41withVector (V n fp) f = withForeignPtr fp $ \p -> do 44withVector (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
47createVector :: Storable a => Int -> IO (Vector a) 50createVector :: Storable a => Int -> IO (Vector a)
48createVector n = do 51createVector 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)