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