@@ -89,7 +89,7 @@ module Data.Array
8989 , delete
9090 , deleteBy
9191
92- , (\\)
92+ , (\\), difference
9393 , intersect
9494 , intersectBy
9595
@@ -101,21 +101,17 @@ module Data.Array
101101 , foldM
102102 ) where
103103
104- import Prelude
104+ import Prelude ( class Monad , class Applicative , class Eq , class Ord , Unit , Ordering (LT, EQ, GT), (>>=), return , eq , const , otherwise , ($), flip , (++), (==), not , (<<<), negate , compare , id , bind , pure , one , (-), zero , (+), (<*>), (<$>), (<))
105105
106- import Control.Alt (Alt , (<|>))
107- import Control.Alternative (Alternative )
108- import Control.Lazy (Lazy , defer )
109- import Control.MonadPlus (MonadPlus )
110- import Control.Plus (Plus )
106+ import Control.Alt ((<|>))
107+ import Control.Alternative (class Alternative )
108+ import Control.Lazy (class Lazy , defer )
111109
112110import Data.Foldable (foldl )
113- import Data.Functor.Invariant (Invariant )
114111import Data.Maybe (Maybe (..), maybe , isJust )
115- import Data.Monoid (Monoid )
116112import Data.Traversable (sequence )
117113import Data.Tuple (Tuple (..))
118- import qualified Data.Maybe.Unsafe as U
114+ import Data.Maybe.Unsafe as U
119115
120116-- | Create an array of one element
121117singleton :: forall a . a -> Array a
@@ -124,11 +120,8 @@ singleton a = [a]
124120-- | Create an array containing a range of integers, including both endpoints.
125121foreign import range :: Int -> Int -> Array Int
126122
127- infix 8 ..
128-
129123-- | An infix synonym for `range`.
130- (..) :: Int -> Int -> Array Int
131- (..) = range
124+ infix 8 range as ..
132125
133126-- | Create an array with repeated instances of a value.
134127foreign import replicate :: forall a . Int -> a -> Array a
@@ -177,13 +170,10 @@ foreign import length :: forall a. Array a -> Int
177170-- | Note, the running time of this function is `O(n)`.
178171foreign import cons :: forall a . a -> Array a -> Array a
179172
180- infixr 6 :
181-
182173-- | An infix alias for `cons`.
183174-- |
184175-- | Note, the running time of this function is `O(n)`.
185- (:) :: forall a . a -> Array a -> Array a
186- (:) = cons
176+ infixr 6 cons as :
187177
188178-- | Append an element to the end of an array, creating a new array.
189179foreign import snoc :: forall a . Array a -> a -> Array a
@@ -265,11 +255,8 @@ foreign import indexImpl :: forall a. (forall r. r -> Maybe r)
265255 -> Int
266256 -> Maybe a
267257
268- infixl 8 !!
269-
270258-- | An infix version of `index`.
271- (!!) :: forall a . Array a -> Int -> Maybe a
272- (!!) = index
259+ infixl 8 index as !!
273260
274261-- | Find the index of the first element equal to the specified element.
275262elemIndex :: forall a . (Eq a ) => a -> Array a -> Maybe Int
@@ -524,13 +511,13 @@ deleteBy :: forall a. (a -> a -> Boolean) -> a -> Array a -> Array a
524511deleteBy _ _ [] = []
525512deleteBy eq x ys = maybe ys (\i -> U .fromJust $ deleteAt i ys) (findIndex (eq x) ys)
526513
527- infix 5 \\
528-
529514-- | Delete the first occurrence of each element in the second array from the
530515-- | first array, creating a new array.
531- (\\) :: forall a . (Eq a ) => Array a -> Array a -> Array a
532- (\\) xs ys | null xs = []
533- | otherwise = uncons' (const xs) (\y ys -> delete y xs \\ ys) ys
516+ difference :: forall a . (Eq a ) => Array a -> Array a -> Array a
517+ difference xs ys | null xs = []
518+ | otherwise = uncons' (const xs) (\z zs -> delete z xs \\ zs) ys
519+
520+ infix 5 difference as \\
534521
535522-- | Calculate the intersection of two arrays, creating a new array.
536523intersect :: forall a . (Eq a ) => Array a -> Array a -> Array a
0 commit comments