@@ -1,8 +1,8 @@
1module Array where
1module Array where
3−{-| A library for manipulating arrays of elements. The elements in an
3+{-| A library for immutable arrays. The elements in an array must have the same
4−array must have the same type. The arrays are implemented in Relaxed
4+type. The arrays are implemented in Relaxed Radix Balanced-Trees for fast
5−Radix Balanced-Trees for fast updating and concating.
5+reads, updates, and concatenation.
7If you use more then one map or zip function on an array, consider turning it
7If you use more then one map or zip function on an array, consider turning it
8into a list before operating on it, and then turning it back into an array.
8into a list before operating on it, and then turning it back into an array.
@@ -132,9 +132,10 @@ get = Native.Array.get
132 safeGet 5 (A.fromList [3,2,1]) == Nothing
132 safeGet 5 (A.fromList [3,2,1]) == Nothing
134safeGet : Int -> Array a -> Maybe a
134safeGet : Int -> Array a -> Maybe a
135−safeGet i array = if Native.Array.length array > i
136+ if i < Native.Array.length array
136− then Just (Native.Array.get i array)
137+ then Just (Native.Array.get i array)
137− else Nothing
138+ else Nothing
139{-| Get the element at the index. If the index is out of range, the given default
140{-| Get the element at the index. If the index is out of range, the given default
140elementis returned.
141elementis returned.
@@ -143,8 +144,10 @@ elementis returned.
143 getWithDefault 0 5 (A.fromList [3,2,1]) == 0
144 getWithDefault 0 5 (A.fromList [3,2,1]) == 0
145getWithDefault : a -> Int -> Array a -> a
146getWithDefault : a -> Int -> Array a -> a
146−getWithDefault default i array = if Native.Array.length array > i
147+getWithDefault default i array =
148+ if i < Native.Array.length array
147− then Native.Array.get i array else default
149+ then Native.Array.get i array
149{-| Set the element at the index. Returns the updated array, or if the index is
152{-| Set the element at the index. Returns the updated array, or if the index is
150out of range, the unaltered array.
153out of range, the unaltered array.