summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2009-04-27 17:25:18 +0000
committerAlberto Ruiz <aruiz@um.es>2009-04-27 17:25:18 +0000
commit0c2c887de10702206ee645452a86674500314948 (patch)
tree935b72efca7b4e65bfa80ba18c2342516aca75d3 /lib/Data/Packed/Internal
parentc210311be639e8774dca25a332542d6b64ce3ca3 (diff)
more defined (|>) and (><) as suggested by Tracy Wadleigh
Diffstat (limited to 'lib/Data/Packed/Internal')
-rw-r--r--lib/Data/Packed/Internal/Vector.hs22
1 files changed, 9 insertions, 13 deletions
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs
index 0e6b3f4..fc8a6be 100644
--- a/lib/Data/Packed/Internal/Vector.hs
+++ b/lib/Data/Packed/Internal/Vector.hs
@@ -91,21 +91,17 @@ inlinePerformIO (IO m) = case m realWorld# of (# _, r #) -> r
91toList :: Storable a => Vector a -> [a] 91toList :: Storable a => Vector a -> [a]
92toList v = safeRead v $ peekArray (dim v) 92toList v = safeRead v $ peekArray (dim v)
93 93
94-- | an alternative to 'fromList' with explicit dimension, used also in the instances for Show (Vector a). 94{- | An alternative to 'fromList' with explicit dimension. The input
95(|>) :: (Storable a) => Int -> [a] -> Vector a 95 list is explicitly truncated if it is too long, so it may safely
96infixl 9 |> 96 be used, for instance, with infinite lists.
97n |> l = if length l == n then fromList l else error "|> with wrong size"
98
99{- | Like '(|>)', but explicitly truncates the list, if it is too long.
100 97
101It may safely be used, for instance, with infinite lists. 98 This is the format used in the instances for Show (Vector a).
102-} 99-}
103(|>|) :: (Storable a) => Int -> [a] -> Vector a 100(|>) :: (Storable a) => Int -> [a] -> Vector a
104infixl 9 |>| 101infixl 9 |>
105n |>| l = if length l' == n then 102n |> l = if length l' == n
106 fromList l' 103 then fromList l'
107 else 104 else error "list too short for |>"
108 error "|>|: list too short"
109 where l' = take n l 105 where l' = take n l
110 106
111 107