diff options
author | Alberto Ruiz <aruiz@um.es> | 2009-04-27 17:25:18 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2009-04-27 17:25:18 +0000 |
commit | 0c2c887de10702206ee645452a86674500314948 (patch) | |
tree | 935b72efca7b4e65bfa80ba18c2342516aca75d3 /lib/Data/Packed/Internal/Vector.hs | |
parent | c210311be639e8774dca25a332542d6b64ce3ca3 (diff) |
more defined (|>) and (><) as suggested by Tracy Wadleigh
Diffstat (limited to 'lib/Data/Packed/Internal/Vector.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Vector.hs | 22 |
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 | |||
91 | toList :: Storable a => Vector a -> [a] | 91 | toList :: Storable a => Vector a -> [a] |
92 | toList v = safeRead v $ peekArray (dim v) | 92 | toList 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 |
96 | infixl 9 |> | 96 | be used, for instance, with infinite lists. |
97 | n |> 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 | ||
101 | It 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 |
104 | infixl 9 |>| | 101 | infixl 9 |> |
105 | n |>| l = if length l' == n then | 102 | n |> 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 | ||