Skip to content

Commit 8c3c33b

Browse files
committed
Merge pull request #36 from purescript/fix-warnings
Fix shadow and pattern warnings
2 parents b4748b1 + 0860761 commit 8c3c33b

File tree

9 files changed

+148
-95
lines changed

9 files changed

+148
-95
lines changed

src/Data/List.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ range :: Int -> Int -> List Int
138138
range start end | start == end = singleton start
139139
| otherwise = go end start (if start > end then 1 else -1) Nil
140140
where
141-
go s e step tail | s == e = (Cons s tail)
142-
| otherwise = go (s + step) e step (Cons s tail)
141+
go s e step rest | s == e = (Cons s rest)
142+
| otherwise = go (s + step) e step (Cons s rest)
143143

144144
-- | Create a list with repeated instances of a value.
145145
replicate :: forall a. Int -> a -> List a
146146
replicate n value = go n Nil
147147
where
148-
go n tail | n <= 0 = tail
149-
| otherwise = go (n - 1) (Cons value tail)
148+
go n rest | n <= 0 = rest
149+
| otherwise = go (n - 1) (Cons value rest)
150150

151151
-- | Perform a monadic action `n` times collecting all of the results.
152152
replicateM :: forall m a. (Monad m) => Int -> m a -> m (List a)

src/Data/List/Lazy.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ range :: Int -> Int -> List Int
162162
range start end | start == end = singleton start
163163
| otherwise = go end start (if start > end then 1 else -1) nil
164164
where
165-
go s e step tail | s == e = (cons s tail)
166-
| otherwise = go (s + step) e step (cons s tail)
165+
go s e step' rest | s == e = (cons s rest)
166+
| otherwise = go (s + step') e step' (cons s rest)
167167

168168
-- | Create a list by repeating an element
169169
repeat :: forall a. a -> List a

src/Data/List/Unsafe.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* global exports */
2+
"use strict";
3+
4+
// module Data.List.Unsafe
5+
6+
exports.unsafeThrow = function (msg) {
7+
throw new Error(msg);
8+
};

src/Data/List/Unsafe.purs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
-- | _Note_: these functions should be used with care, and may result in unspecified
44
-- | behavior, including runtime exceptions.
55

6-
module Data.List.Unsafe where
6+
module Data.List.Unsafe
7+
( head
8+
, tail
9+
, last
10+
, init
11+
) where
712

813
import Prelude
914
import Data.List (List(..))
@@ -13,23 +18,29 @@ import Data.List (List(..))
1318
-- | Running time: `O(1)`.
1419
head :: forall a. List a -> a
1520
head (Cons x _) = x
21+
head Nil = unsafeThrow "Data.List.Unsafe.head called on empty list"
1622

1723
-- | Get all but the first element of a non-empty list.
1824
-- |
1925
-- | Running time: `O(1)`
2026
tail :: forall a. List a -> List a
2127
tail (Cons _ xs) = xs
28+
tail Nil = unsafeThrow "Data.List.Unsafe.tail called on empty list"
2229

2330
-- | Get the last element of a non-empty list.
2431
-- |
2532
-- | Running time: `O(n)`
2633
last :: forall a. List a -> a
2734
last (Cons x Nil) = x
2835
last (Cons _ xs) = last xs
36+
last Nil = unsafeThrow "Data.List.Unsafe.last called on empty list"
2937

3038
-- | Get all but the last element of a non-empty list.
3139
-- |
3240
-- | Running time: `O(n)`
3341
init :: forall a. List a -> List a
3442
init (Cons x Nil) = Nil
3543
init (Cons x xs) = Cons x (init xs)
44+
init Nil = unsafeThrow "Data.List.Unsafe.init called on empty list"
45+
46+
foreign import unsafeThrow :: forall a. String -> a

src/Data/List/ZipList.purs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,3 @@ instance plusZipList :: Plus ZipList where
6565
empty = mempty
6666

6767
instance alternativeZipList :: Alternative ZipList
68-
69-

test/Test/Data/List.purs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import Test.Assert (assert)
1010

1111
testList = do
1212

13-
log "singleton should construct an array with a single value"
13+
log "singleton should construct an list with a single value"
1414
assert $ singleton 1 == toList [1]
1515
assert $ singleton "foo" == toList ["foo"]
1616
assert $ singleton nil == toList [toList []]
1717

18-
log "range should create an inclusive array of integers for the specified start and end"
18+
log "range should create an inclusive list of integers for the specified start and end"
1919
assert $ (range 0 5) == toList [0, 1, 2, 3, 4, 5]
2020
assert $ (range 2 (-3)) == toList [2, 1, 0, -1, -2, -3]
2121

22-
log "replicate should produce an array containg an item a specified number of times"
22+
log "replicate should produce an list containg an item a specified number of times"
2323
assert $ replicate 3 true == toList [true, true, true]
2424
assert $ replicate 1 "foo" == toList ["foo"]
2525
assert $ replicate 0 "foo" == toList []
@@ -34,88 +34,88 @@ testList = do
3434
-- some
3535
-- many
3636

37-
log "null should return false for non-empty arrays"
37+
log "null should return false for non-empty lists"
3838
assert $ null (toList [1]) == false
3939
assert $ null (toList [1, 2, 3]) == false
4040

41-
log "null should return true for an empty array"
41+
log "null should return true for an empty list"
4242
assert $ null nil == true
4343

44-
log "length should return the number of items in an array"
44+
log "length should return the number of items in an list"
4545
assert $ length nil == 0
4646
assert $ length (toList [1]) == 1
4747
assert $ length (toList [1, 2, 3, 4, 5]) == 5
4848

49-
log "snoc should add an item to the end of an array"
49+
log "snoc should add an item to the end of an list"
5050
assert $ toList [1, 2, 3] `snoc` 4 == toList [1, 2, 3, 4]
5151
assert $ nil `snoc` 1 == toList [1]
5252

53-
log "insert should add an item at the appropriate place in a sorted array"
53+
log "insert should add an item at the appropriate place in a sorted list"
5454
assert $ insert 1.5 (toList [1.0, 2.0, 3.0]) == toList [1.0, 1.5, 2.0, 3.0]
5555
assert $ insert 4 (toList [1, 2, 3]) == toList [1, 2, 3, 4]
5656
assert $ insert 0 (toList [1, 2, 3]) == toList [0, 1, 2, 3]
5757

58-
log "insertBy should add an item at the appropriate place in a sorted array using the specified comparison"
58+
log "insertBy should add an item at the appropriate place in a sorted list using the specified comparison"
5959
assert $ insertBy (flip compare) 4 (toList [1, 2, 3]) == toList [4, 1, 2, 3]
6060
assert $ insertBy (flip compare) 0 (toList [1, 2, 3]) == toList [1, 2, 3, 0]
6161

62-
log "head should return a Just-wrapped first value of a non-empty array"
62+
log "head should return a Just-wrapped first value of a non-empty list"
6363
assert $ head (toList ["foo", "bar"]) == Just "foo"
6464

65-
log "head should return Nothing for an empty array"
65+
log "head should return Nothing for an empty list"
6666
assert $ head nil == Nothing
6767

68-
log "last should return a Just-wrapped last value of a non-empty array"
68+
log "last should return a Just-wrapped last value of a non-empty list"
6969
assert $ last (toList ["foo", "bar"]) == Just "bar"
7070

71-
log "last should return Nothing for an empty array"
71+
log "last should return Nothing for an empty list"
7272
assert $ last nil == Nothing
7373

74-
log "tail should return a Just-wrapped array containing all the items in an array apart from the first for a non-empty array"
74+
log "tail should return a Just-wrapped list containing all the items in an list apart from the first for a non-empty list"
7575
assert $ tail (toList ["foo", "bar", "baz"]) == Just (toList ["bar", "baz"])
7676

77-
log "tail should return Nothing for an empty array"
77+
log "tail should return Nothing for an empty list"
7878
assert $ tail nil == Nothing
7979

80-
log "init should return a Just-wrapped array containing all the items in an array apart from the first for a non-empty array"
80+
log "init should return a Just-wrapped list containing all the items in an list apart from the first for a non-empty list"
8181
assert $ init (toList ["foo", "bar", "baz"]) == Just (toList ["foo", "bar"])
8282

83-
log "init should return Nothing for an empty array"
83+
log "init should return Nothing for an empty list"
8484
assert $ init nil == Nothing
8585

86-
log "uncons should return nothing when used on an empty array"
86+
log "uncons should return nothing when used on an empty list"
8787
assert $ isNothing (uncons nil)
8888

89-
log "uncons should split an array into a head and tail record when there is at least one item"
89+
log "uncons should split an list into a head and tail record when there is at least one item"
9090
let u1 = uncons (toList [1])
9191
assert $ (fromJust u1).head == 1
9292
assert $ (fromJust u1).tail == toList []
9393
let u2 = uncons (toList [1, 2, 3])
9494
assert $ (fromJust u2).head == 1
9595
assert $ (fromJust u2).tail == toList [2, 3]
9696

97-
log "(!!) should return Just x when the index is within the bounds of the array"
97+
log "(!!) should return Just x when the index is within the bounds of the list"
9898
assert $ toList [1, 2, 3] !! 0 == (Just 1)
9999
assert $ toList [1, 2, 3] !! 1 == (Just 2)
100100
assert $ toList [1, 2, 3] !! 2 == (Just 3)
101101

102-
log "(!!) should return Nothing when the index is outside of the bounds of the array"
102+
log "(!!) should return Nothing when the index is outside of the bounds of the list"
103103
assert $ toList [1, 2, 3] !! 6 == Nothing
104104
assert $ toList [1, 2, 3] !! (-1) == Nothing
105105

106-
log "elemIndex should return the index of an item that a predicate returns true for in an array"
106+
log "elemIndex should return the index of an item that a predicate returns true for in an list"
107107
assert $ elemIndex 1 (toList [1, 2, 1]) == Just 0
108108
assert $ elemIndex 4 (toList [1, 2, 1]) == Nothing
109109

110-
log "elemLastIndex should return the last index of an item in an array"
110+
log "elemLastIndex should return the last index of an item in an list"
111111
assert $ elemLastIndex 1 (toList [1, 2, 1]) == Just 2
112112
assert $ elemLastIndex 4 (toList [1, 2, 1]) == Nothing
113113

114-
log "findIndex should return the index of an item that a predicate returns true for in an array"
114+
log "findIndex should return the index of an item that a predicate returns true for in an list"
115115
assert $ findIndex (/= 1) (toList [1, 2, 1]) == Just 1
116116
assert $ findIndex (== 3) (toList [1, 2, 1]) == Nothing
117117

118-
log "findLastIndex should return the last index of an item in an array"
118+
log "findLastIndex should return the last index of an item in an list"
119119
assert $ findLastIndex (/= 1) (toList [2, 1, 2]) == Just 2
120120
assert $ findLastIndex (== 3) (toList [2, 1, 2]) == Nothing
121121

@@ -159,11 +159,11 @@ testList = do
159159
log "alterAt should return Nothing if the index is out of range"
160160
assert $ (alterAt 1 (Just <<< (+ 1)) nil) == Nothing
161161

162-
log "reverse should reverse the order of items in an array"
162+
log "reverse should reverse the order of items in an list"
163163
assert $ (reverse (toList [1, 2, 3])) == toList [3, 2, 1]
164164
assert $ (reverse nil) == nil
165165

166-
log "concat should join an array of arrays"
166+
log "concat should join an list of lists"
167167
assert $ (concat (toList [toList [1, 2], toList [3, 4]])) == toList [1, 2, 3, 4]
168168
assert $ (concat (toList [toList [1], nil])) == toList [1]
169169
assert $ (concat (toList [nil, nil])) == nil
@@ -178,10 +178,10 @@ testList = do
178178
assert $ filterM (Just <<< odd) (range 0 10) == Just (toList [1, 3, 5, 7, 9])
179179
assert $ filterM (const Nothing) (range 0 10) == Nothing
180180

181-
log "mapMaybe should transform every item in an array, throwing out Nothing values"
181+
log "mapMaybe should transform every item in an list, throwing out Nothing values"
182182
assert $ mapMaybe (\x -> if x /= 0 then Just x else Nothing) (toList [0, 1, 0, 0, 2, 3]) == toList [1, 2, 3]
183183

184-
log "catMaybe should take an array of Maybe values and throw out Nothings"
184+
log "catMaybe should take an list of Maybe values and throw out Nothings"
185185
assert $ catMaybes (toList [Nothing, Just 2, Nothing, Just 4]) == toList [2, 4]
186186

187187
log "sort should reorder a list into ascending order based on the result of compare"
@@ -190,38 +190,38 @@ testList = do
190190
log "sortBy should reorder a list into ascending order based on the result of a comparison function"
191191
assert $ sortBy (flip compare) (toList [1, 3, 2, 5, 6, 4]) == toList [6, 5, 4, 3, 2, 1]
192192

193-
log "take should keep the specified number of items from the front of an array, discarding the rest"
193+
log "take should keep the specified number of items from the front of an list, discarding the rest"
194194
assert $ (take 1 (toList [1, 2, 3])) == toList [1]
195195
assert $ (take 2 (toList [1, 2, 3])) == toList [1, 2]
196196
assert $ (take 1 nil) == nil
197197

198-
log "takeWhile should keep all values that match a predicate from the front of an array"
198+
log "takeWhile should keep all values that match a predicate from the front of an list"
199199
assert $ (takeWhile (/= 2) (toList [1, 2, 3])) == toList [1]
200200
assert $ (takeWhile (/= 3) (toList [1, 2, 3])) == toList [1, 2]
201201
assert $ (takeWhile (/= 1) nil) == nil
202202

203-
log "drop should remove the specified number of items from the front of an array"
203+
log "drop should remove the specified number of items from the front of an list"
204204
assert $ (drop 1 (toList [1, 2, 3])) == toList [2, 3]
205205
assert $ (drop 2 (toList [1, 2, 3])) == toList [3]
206206
assert $ (drop 1 nil) == nil
207207

208-
log "dropWhile should remove all values that match a predicate from the front of an array"
208+
log "dropWhile should remove all values that match a predicate from the front of an list"
209209
assert $ (dropWhile (/= 1) (toList [1, 2, 3])) == toList [1, 2, 3]
210210
assert $ (dropWhile (/= 2) (toList [1, 2, 3])) == toList [2, 3]
211211
assert $ (dropWhile (/= 1) nil) == nil
212212

213-
log "span should split an array in two based on a predicate"
213+
log "span should split an list in two based on a predicate"
214214
let spanResult = span (< 4) (toList [1, 2, 3, 4, 5, 6, 7])
215215
assert $ spanResult.init == toList [1, 2, 3]
216216
assert $ spanResult.rest == toList [4, 5, 6, 7]
217217

218-
log "group should group consecutive equal elements into arrays"
218+
log "group should group consecutive equal elements into lists"
219219
assert $ group (toList [1, 2, 2, 3, 3, 3, 1]) == toList [toList [1], toList [2, 2], toList [3, 3, 3], toList [1]]
220220

221-
log "group' should sort then group consecutive equal elements into arrays"
221+
log "group' should sort then group consecutive equal elements into lists"
222222
assert $ group' (toList [1, 2, 2, 3, 3, 3, 1]) == toList [toList [1, 1], toList [2, 2], toList [3, 3, 3]]
223223

224-
log "groupBy should group consecutive equal elements into arrays based on an equivalence relation"
224+
log "groupBy should group consecutive equal elements into lists based on an equivalence relation"
225225
assert $ groupBy (\x y -> odd x && odd y) (toList [1, 1, 2, 2, 3, 3]) == toList [toList [1, 1], toList [2], toList [2], toList [3, 3]]
226226

227227
log "nub should remove duplicate items from the list"
@@ -231,28 +231,28 @@ testList = do
231231
let nubPred = \x y -> if odd x then false else x == y
232232
assert $ nubBy nubPred (toList [1, 2, 2, 3, 3, 4, 4, 1]) == toList [1, 2, 3, 3, 4, 1]
233233

234-
log "union should produce the union of two arrays"
234+
log "union should produce the union of two lists"
235235
assert $ union (toList [1, 2, 3]) (toList [2, 3, 4]) == toList [1, 2, 3, 4]
236236
assert $ union (toList [1, 1, 2, 3]) (toList [2, 3, 4]) == toList [1, 1, 2, 3, 4]
237237

238-
log "unionBy should produce the union of two arrays using the specified equality relation"
238+
log "unionBy should produce the union of two lists using the specified equality relation"
239239
assert $ unionBy (\_ y -> y < 5) (toList [1, 2, 3]) (toList [2, 3, 4, 5, 6]) == toList [1, 2, 3, 5, 6]
240240

241-
log "delete should remove the first matching item from an array"
241+
log "delete should remove the first matching item from an list"
242242
assert $ delete 1 (toList [1, 2, 1]) == toList [2, 1]
243243
assert $ delete 2 (toList [1, 2, 1]) == toList [1, 1]
244244

245-
log "deleteBy should remove the first equality-relation-matching item from an array"
245+
log "deleteBy should remove the first equality-relation-matching item from an list"
246246
assert $ deleteBy (/=) 2 (toList [1, 2, 1]) == toList [2, 1]
247247
assert $ deleteBy (/=) 1 (toList [1, 2, 1]) == toList [1, 1]
248248

249249
log "(\\\\) should return the difference between two lists"
250250
assert $ toList [1, 2, 3, 4, 3, 2, 1] \\ toList [1, 1, 2, 3] == toList [4, 3, 2]
251251

252-
log "intersect should return the intersection of two arrays"
252+
log "intersect should return the intersection of two lists"
253253
assert $ intersect (toList [1, 2, 3, 4, 3, 2, 1]) (toList [1, 1, 2, 3]) == toList [1, 2, 3, 3, 2, 1]
254254

255-
log "intersectBy should return the intersection of two arrays using the specified equivalence relation"
255+
log "intersectBy should return the intersection of two lists using the specified equivalence relation"
256256
assert $ intersectBy (\x y -> (x * 2) == y) (toList [1, 2, 3]) (toList [2, 6]) == toList [1, 3]
257257

258258
log "zipWith should use the specified function to zip two lists together"

0 commit comments

Comments
 (0)