Skip to content

Commit eee0d1b

Browse files
committed
Merge pull request #58 from telser/purescript-0.8-warnings
Fix warnings generated by purescript 0.8.0
2 parents e47d505 + 3ddd885 commit eee0d1b

File tree

6 files changed

+84
-65
lines changed

6 files changed

+84
-65
lines changed

src/Data/Array.purs

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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

112110
import Data.Foldable (foldl)
113-
import Data.Functor.Invariant (Invariant)
114111
import Data.Maybe (Maybe(..), maybe, isJust)
115-
import Data.Monoid (Monoid)
116112
import Data.Traversable (sequence)
117113
import 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
121117
singleton :: forall a. a -> Array a
@@ -124,11 +120,8 @@ singleton a = [a]
124120
-- | Create an array containing a range of integers, including both endpoints.
125121
foreign 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.
134127
foreign 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)`.
178171
foreign 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.
189179
foreign import snoc :: forall a. Array a -> a -> Array a
@@ -196,7 +186,7 @@ insert = insertBy compare
196186
-- | determine the ordering of elements.
197187
insertBy :: forall a. (a -> a -> Ordering) -> a -> Array a -> Array a
198188
insertBy cmp x ys =
199-
let i = maybe 0 (+ 1) (findLastIndex (\y -> cmp x y == GT) ys)
189+
let i = maybe 0 (_ + 1) (findLastIndex (\y -> cmp x y == GT) ys)
200190
in U.fromJust (insertAt i x ys)
201191

202192
--------------------------------------------------------------------------------
@@ -265,19 +255,16 @@ 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.
275262
elemIndex :: forall a. (Eq a) => a -> Array a -> Maybe Int
276-
elemIndex x = findIndex (== x)
263+
elemIndex x = findIndex (_ == x)
277264

278265
-- | Find the index of the last element equal to the specified element.
279266
elemLastIndex :: forall a. (Eq a) => a -> Array a -> Maybe Int
280-
elemLastIndex x = findLastIndex (== x)
267+
elemLastIndex x = findLastIndex (_ == x)
281268

282269
-- | Find the first index for which a predicate holds.
283270
findIndex :: forall a. (a -> Boolean) -> Array a -> Maybe Int
@@ -524,13 +511,13 @@ deleteBy :: forall a. (a -> a -> Boolean) -> a -> Array a -> Array a
524511
deleteBy _ _ [] = []
525512
deleteBy 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.
536523
intersect :: forall a. (Eq a) => Array a -> Array a -> Array a

src/Data/Array/Unsafe.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module Data.Array.Unsafe where
77

8-
import Prelude
8+
import Prelude ((-))
99

1010
import Data.Array (length, slice)
1111

test/Test/Data/Array.purs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
module Test.Data.Array (testArray) where
22

3-
import Prelude
4-
import Control.Monad.Eff.Console (log)
5-
import Data.Array
3+
import Prelude ((*), zero, (/=), mod, (==), ($), (+), bind, show, (<), (&&), compare, flip, const, (<<<), map, negate, unit, Unit)
4+
import Control.Monad.Eff (Eff)
5+
import Control.Monad.Eff.Console (log, CONSOLE)
6+
import Data.Array (range, foldM, unzip, zip, zipWithA, zipWith, intersectBy, intersect, (\\), deleteBy, delete, unionBy, union, nubBy, nub, groupBy, group', group, span, dropWhile, drop, takeWhile, take, sortBy, sort, catMaybes, mapMaybe, filterM, filter, concat, concatMap, reverse, alterAt, modifyAt, updateAt, deleteAt, insertAt, findLastIndex, findIndex, elemLastIndex, elemIndex, (!!), uncons, init, tail, last, head, insertBy, insert, snoc, (:), length, null, replicate, replicateM, singleton)
67
import Data.Maybe (Maybe(..), isNothing)
78
import Data.Maybe.Unsafe (fromJust)
89
import Data.Tuple (Tuple(..))
9-
import Test.Assert (assert)
10-
10+
import Test.Assert (assert, ASSERT)
11+
12+
testArray :: forall t.
13+
Eff
14+
( console :: CONSOLE
15+
, assert :: ASSERT
16+
| t
17+
)
18+
Unit
1119
testArray = do
1220

1321
log "singleton should construct an array with a single value"
@@ -121,12 +129,12 @@ testArray = do
121129
assert $ (elemLastIndex 4 [1, 2, 1]) == Nothing
122130

123131
log "findIndex should return the index of an item that a predicate returns true for in an array"
124-
assert $ (findIndex (/= 1) [1, 2, 1]) == Just 1
125-
assert $ (findIndex (== 3) [1, 2, 1]) == Nothing
132+
assert $ (findIndex (_ /= 1) [1, 2, 1]) == Just 1
133+
assert $ (findIndex (_ == 3) [1, 2, 1]) == Nothing
126134

127135
log "findLastIndex should return the last index of an item in an array"
128-
assert $ (findLastIndex (/= 1) [2, 1, 2]) == Just 2
129-
assert $ (findLastIndex (== 3) [2, 1, 2]) == Nothing
136+
assert $ (findLastIndex (_ /= 1) [2, 1, 2]) == Just 2
137+
assert $ (findLastIndex (_ == 3) [2, 1, 2]) == Nothing
130138

131139
log "insertAt should add an item at the specified index"
132140
assert $ (insertAt 0 1 [2, 3]) == Just [1, 2, 3]
@@ -151,11 +159,11 @@ testArray = do
151159
assert $ (updateAt 1 9 nil) == Nothing
152160

153161
log "modifyAt should update an item at the specified index"
154-
assert $ (modifyAt 0 (+ 1) [1, 2, 3]) == Just [2, 2, 3]
155-
assert $ (modifyAt 1 (+ 1) [1, 2, 3]) == Just [1, 3, 3]
162+
assert $ (modifyAt 0 (_ + 1) [1, 2, 3]) == Just [2, 2, 3]
163+
assert $ (modifyAt 1 (_ + 1) [1, 2, 3]) == Just [1, 3, 3]
156164

157165
log "modifyAt should return Nothing if the index is out of range"
158-
assert $ (modifyAt 1 (+ 1) nil) == Nothing
166+
assert $ (modifyAt 1 (_ + 1) nil) == Nothing
159167

160168
log "alterAt should update an item at the specified index when the function returns Just"
161169
assert $ (alterAt 0 (Just <<< (+ 1)) [1, 2, 3]) == Just [2, 2, 3]
@@ -205,22 +213,22 @@ testArray = do
205213
assert $ (take 1 nil) == nil
206214

207215
log "takeWhile should keep all values that match a predicate from the front of an array"
208-
assert $ (takeWhile (/= 2) [1, 2, 3]) == [1]
209-
assert $ (takeWhile (/= 3) [1, 2, 3]) == [1, 2]
210-
assert $ (takeWhile (/= 1) nil) == nil
216+
assert $ (takeWhile (_ /= 2) [1, 2, 3]) == [1]
217+
assert $ (takeWhile (_ /= 3) [1, 2, 3]) == [1, 2]
218+
assert $ (takeWhile (_ /= 1) nil) == nil
211219

212220
log "drop should remove the specified number of items from the front of an array"
213221
assert $ (drop 1 [1, 2, 3]) == [2, 3]
214222
assert $ (drop 2 [1, 2, 3]) == [3]
215223
assert $ (drop 1 nil) == nil
216224

217225
log "dropWhile should remove all values that match a predicate from the front of an array"
218-
assert $ (dropWhile (/= 1) [1, 2, 3]) == [1, 2, 3]
219-
assert $ (dropWhile (/= 2) [1, 2, 3]) == [2, 3]
220-
assert $ (dropWhile (/= 1) nil) == nil
226+
assert $ (dropWhile (_ /= 1) [1, 2, 3]) == [1, 2, 3]
227+
assert $ (dropWhile (_ /= 2) [1, 2, 3]) == [2, 3]
228+
assert $ (dropWhile (_ /= 1) nil) == nil
221229

222230
log "span should split an array in two based on a predicate"
223-
let spanResult = span (< 4) [1, 2, 3, 4, 5, 6, 7]
231+
let spanResult = span (_ < 4) [1, 2, 3, 4, 5, 6, 7]
224232
assert $ spanResult.init == [1, 2, 3]
225233
assert $ spanResult.rest == [4, 5, 6, 7]
226234

test/Test/Data/Array/ST.purs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
module Test.Data.Array.ST (testArrayST) where
22

3-
import Prelude
4-
import Control.Monad.Eff.Console (log, print)
5-
import Control.Monad.Eff (runPure)
3+
import Prelude (bind, (+), (*), (==), ($), return, negate, not, Unit)
4+
import Control.Monad.Eff.Console (log, CONSOLE)
5+
import Control.Monad.Eff (runPure, Eff)
66
import Control.Monad.ST (runST)
7-
import Data.Array ()
8-
import Data.Array.ST
7+
import Data.Array.ST (toAssocArray, thaw, spliceSTArray, runSTArray, pokeSTArray, emptySTArray, peekSTArray, pushAllSTArray, pushSTArray, freeze)
98
import Data.Foldable (all)
109
import Data.Maybe (Maybe(..), isNothing)
11-
import Test.Assert (assert)
12-
10+
import Test.Assert (assert, ASSERT)
11+
12+
testArrayST :: forall t.
13+
Eff
14+
( console :: CONSOLE
15+
, assert :: ASSERT
16+
| t
17+
)
18+
Unit
1319
testArrayST = do
1420

1521
log "emptySTArray should produce an empty array"

test/Test/Data/Array/Unsafe.purs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
module Test.Data.Array.Unsafe (testArrayUnsafe) where
22

3-
import Prelude
4-
import Control.Monad.Eff.Console (log)
5-
import Data.Array.Unsafe
6-
import Test.Assert (assert)
3+
import Prelude ((==), ($), bind, Unit)
4+
import Control.Monad.Eff (Eff)
5+
import Control.Monad.Eff.Console (log, CONSOLE)
6+
import Data.Array.Unsafe (init, last, tail, head)
7+
import Test.Assert (assert, ASSERT)
78

9+
testArrayUnsafe :: forall t.
10+
Eff
11+
( console :: CONSOLE
12+
, assert :: ASSERT
13+
| t
14+
)
15+
Unit
816
testArrayUnsafe = do
917

1018
log "head should return the first item in an array"

test/Test/Main.purs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
module Test.Main where
22

3-
import Prelude
4-
import Test.Data.Array
5-
import Test.Data.Array.ST
6-
import Test.Data.Array.Unsafe
3+
import Prelude (bind, Unit)
4+
import Control.Monad.Eff (Eff)
5+
import Control.Monad.Eff.Console (CONSOLE)
6+
import Test.Assert (ASSERT)
7+
import Test.Data.Array (testArray)
8+
import Test.Data.Array.ST (testArrayST)
9+
import Test.Data.Array.Unsafe (testArrayUnsafe)
710

11+
main :: forall t.
12+
Eff
13+
( console :: CONSOLE
14+
, assert :: ASSERT
15+
| t
16+
)
17+
Unit
818
main = do
919
testArray
1020
testArrayST

0 commit comments

Comments
 (0)