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.hs6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs
index 76bd4d1..082e09d 100644
--- a/lib/Data/Packed/Internal/Vector.hs
+++ b/lib/Data/Packed/Internal/Vector.hs
@@ -80,6 +80,8 @@ fromList l = unsafePerformIO $ do
80 f // vec v // check "fromList" [] 80 f // vec v // check "fromList" []
81 return v 81 return v
82 82
83safeRead v f = unsafePerformIO $ withForeignPtr (fptr v) $ const $ f (ptr v)
84
83{- | extracts the Vector elements to a list 85{- | extracts the Vector elements to a list
84 86
85@> toList (linspace 5 (1,10)) 87@> toList (linspace 5 (1,10))
@@ -87,7 +89,7 @@ fromList l = unsafePerformIO $ do
87 89
88-} 90-}
89toList :: Storable a => Vector a -> [a] 91toList :: Storable a => Vector a -> [a]
90toList v = unsafePerformIO $ peekArray (dim v) (ptr v) 92toList v = safeRead v $ peekArray (dim v)
91 93
92-- | an alternative to 'fromList' with explicit dimension, used also in the instances for Show (Vector a). 94-- | an alternative to 'fromList' with explicit dimension, used also in the instances for Show (Vector a).
93(|>) :: (Storable a) => Int -> [a] -> Vector a 95(|>) :: (Storable a) => Int -> [a] -> Vector a
@@ -96,7 +98,7 @@ n |> l = if length l == n then fromList l else error "|> with wrong size"
96 98
97-- | access to Vector elements without range checking 99-- | access to Vector elements without range checking
98at' :: Storable a => Vector a -> Int -> a 100at' :: Storable a => Vector a -> Int -> a
99at' v n = unsafePerformIO $ peekElemOff (ptr v) n 101at' v n = safeRead v $ flip peekElemOff n
100 102
101-- | access to Vector elements with range checking. 103-- | access to Vector elements with range checking.
102at :: Storable a => Vector a -> Int -> a 104at :: Storable a => Vector a -> Int -> a