summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Vector.hs
diff options
context:
space:
mode:
authorTracy Wadleigh <tracy.wadleigh@gmail.com>2009-04-24 13:58:33 +0000
committerTracy Wadleigh <tracy.wadleigh@gmail.com>2009-04-24 13:58:33 +0000
commitc210311be639e8774dca25a332542d6b64ce3ca3 (patch)
tree032457af80ff755d97a3e7e1922ceaf5eaf2aa62 /lib/Data/Packed/Internal/Vector.hs
parent3ccfccc82aa1cf374af1b822087fb6c4fd41b3c3 (diff)
More defined list-to-V/M operators: (|>|), (>|<).
Provides analogs of the (|>) and (><) operators that first apply an appropriate 'take' to the given lists so that they may be safely used on lists that are too long (or infinite) -- a feature I find particularly useful from the interactive prompt. As these operators are more defined, I would ask the package maintainer to consider, rather than adding (|>|) and (>|<), just updating the definitions of (|>) and (><) with the new semantics.
Diffstat (limited to 'lib/Data/Packed/Internal/Vector.hs')
-rw-r--r--lib/Data/Packed/Internal/Vector.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs
index d410c4d..0e6b3f4 100644
--- a/lib/Data/Packed/Internal/Vector.hs
+++ b/lib/Data/Packed/Internal/Vector.hs
@@ -96,6 +96,19 @@ toList v = safeRead v $ peekArray (dim v)
96infixl 9 |> 96infixl 9 |>
97n |> l = if length l == n then fromList l else error "|> with wrong size" 97n |> l = if length l == n then fromList l else error "|> with wrong size"
98 98
99{- | Like '(|>)', but explicitly truncates the list, if it is too long.
100
101It may safely be used, for instance, with infinite lists.
102-}
103(|>|) :: (Storable a) => Int -> [a] -> Vector a
104infixl 9 |>|
105n |>| l = if length l' == n then
106 fromList l'
107 else
108 error "|>|: list too short"
109 where l' = take n l
110
111
99-- | access to Vector elements without range checking 112-- | access to Vector elements without range checking
100at' :: Storable a => Vector a -> Int -> a 113at' :: Storable a => Vector a -> Int -> a
101at' v n = safeRead v $ flip peekElemOff n 114at' v n = safeRead v $ flip peekElemOff n