Skip to content

Commit 61e9c15

Browse files
authored
Merge pull request #149 from purescript/compiler/0.12
Updates for 0.12
2 parents ab3189f + ea86885 commit 61e9c15

File tree

16 files changed

+140
-116
lines changed

16 files changed

+140
-116
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/bower_components/
55
/node_modules/
66
/output/
7+
package-lock.json

LICENSE

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,26 @@
1-
Copyright (c) 2014 PureScript
1+
Copyright 2018 PureScript
22

3-
Permission is hereby granted, free of charge, to any person
4-
obtaining a copy of this software and associated documentation
5-
files (the "Software"), to deal in the Software without
6-
restriction, including without limitation the rights to use,
7-
copy, modify, merge, publish, distribute, sublicense, and/or sell
8-
copies of the Software, and to permit persons to whom the
9-
Software is furnished to do so, subject to the following
10-
conditions:
3+
Redistribution and use in source and binary forms, with or without modification,
4+
are permitted provided that the following conditions are met:
115

12-
The above copyright notice and this permission notice shall be
13-
included in all copies or substantial portions of the Software.
6+
1. Redistributions of source code must retain the above copyright notice, this
7+
list of conditions and the following disclaimer.
148

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22-
OTHER DEALINGS IN THE SOFTWARE.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation and/or
11+
other materials provided with the distribution.
2312

24-
-----------------------------------------------------------------------------
25-
26-
The Glasgow Haskell Compiler License
27-
28-
Copyright 2004, The University Court of the University of Glasgow.
29-
All rights reserved.
30-
31-
Redistribution and use in source and binary forms, with or without
32-
modification, are permitted provided that the following conditions are met:
33-
34-
- Redistributions of source code must retain the above copyright notice,
35-
this list of conditions and the following disclaimer.
36-
37-
- Redistributions in binary form must reproduce the above copyright notice,
38-
this list of conditions and the following disclaimer in the documentation
39-
and/or other materials provided with the distribution.
40-
41-
- Neither name of the University nor the names of its contributors may be
42-
used to endorse or promote products derived from this software without
13+
3. Neither the name of the copyright holder nor the names of its contributors
14+
may be used to endorse or promote products derived from this software without
4315
specific prior written permission.
4416

45-
THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
46-
GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
47-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
48-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
49-
UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
50-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
52-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
53-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54-
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55-
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
56-
DAMAGE.
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

bower.json

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"authors": [
55
"Phil Freeman <paf31@cantab.net>"
66
],
7-
"description": "Linked lists",
8-
"license": "MIT",
7+
"license": "BSD-3-Clause",
98
"repository": {
109
"type": "git",
1110
"url": "git://github.com/purescript/purescript-lists.git"
@@ -20,17 +19,23 @@
2019
"package.json"
2120
],
2221
"dependencies": {
23-
"purescript-lazy": "^3.0.0",
24-
"purescript-nonempty": "^4.0.0",
25-
"purescript-tailrec": "^3.3.0",
26-
"purescript-unfoldable": "^3.0.0",
27-
"purescript-partial": "^1.0.0",
28-
"purescript-foldable-traversable": "^3.4.0"
22+
"purescript-bifunctors": "^4.0.0",
23+
"purescript-control": "^4.0.0",
24+
"purescript-foldable-traversable": "^4.0.0",
25+
"purescript-lazy": "^4.0.0",
26+
"purescript-maybe": "^4.0.0",
27+
"purescript-newtype": "^3.0.0",
28+
"purescript-nonempty": "^5.0.0",
29+
"purescript-partial": "^2.0.0",
30+
"purescript-prelude": "^4.0.0",
31+
"purescript-tailrec": "^4.0.0",
32+
"purescript-tuples": "^5.0.0",
33+
"purescript-unfoldable": "^4.0.0"
2934
},
3035
"devDependencies": {
31-
"purescript-arrays": "^4.0.0",
32-
"purescript-assert": "^3.0.0",
33-
"purescript-console": "^3.0.0",
34-
"purescript-math": "^2.0.0"
36+
"purescript-arrays": "^5.0.0",
37+
"purescript-assert": "^4.0.0",
38+
"purescript-console": "^4.0.0",
39+
"purescript-math": "^2.1.1"
3540
}
3641
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
55
"build": "pulp build -- --censor-lib --strict",
6-
"test": "pulp test"
6+
"test": "pulp test --check-main-type Effect.Effect"
77
},
88
"devDependencies": {
9-
"pulp": "^11.0.0",
10-
"purescript-psa": "^0.5.1",
11-
"rimraf": "^2.6.1"
9+
"pulp": "^12.2.0",
10+
"purescript-psa": "^0.6.0",
11+
"rimraf": "^2.6.2"
1212
}
1313
}

src/Data/List.purs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ reverse = go Nil
372372
-- |
373373
-- | Running time: `O(n)`, where `n` is the total number of elements.
374374
concat :: forall a. List (List a) -> List a
375-
concat = (_ >>= id)
375+
concat = (_ >>= identity)
376376

377377
-- | Apply a function to each element in a list, and flatten the results
378378
-- | into a single, new list.
@@ -423,7 +423,7 @@ mapMaybe f = go Nil
423423
-- | Filter a list of optional values, keeping only the elements which contain
424424
-- | a value.
425425
catMaybes :: forall a. List (Maybe a) -> List a
426-
catMaybes = mapMaybe id
426+
catMaybes = mapMaybe identity
427427

428428

429429
-- | Apply a function to each element and its index in a list starting at 0.
@@ -617,6 +617,16 @@ partition p xs = foldr select { no: Nil, yes: Nil } xs
617617
then { no, yes: x : yes }
618618
else { no: x : no, yes }
619619

620+
-- | Returns all final segments of the argument, longest first. For example,
621+
-- |
622+
-- | ```purescript
623+
-- | tails (1 : 2 : 3 : Nil) == ((1 : 2 : 3 : Nil) : (2 : 3 : Nil) : (3 : Nil) : (Nil) : Nil)
624+
-- | ```
625+
-- | Running time: `O(n)`
626+
tails :: forall a. List a -> List (List a)
627+
tails Nil = singleton Nil
628+
tails list@(Cons _ tl)= list : tails tl
629+
620630
--------------------------------------------------------------------------------
621631
-- Set-like operations ---------------------------------------------------------
622632
--------------------------------------------------------------------------------

src/Data/List/Lazy.purs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ reverse xs = Z.defer \_ -> foldl (flip cons) nil xs
409409
-- |
410410
-- | Running time: `O(n)`, where `n` is the total number of elements.
411411
concat :: forall a. List (List a) -> List a
412-
concat = (_ >>= id)
412+
concat = (_ >>= identity)
413413

414414
-- | Apply a function to each element in a list, and flatten the results
415415
-- | into a single, new list.
@@ -463,7 +463,7 @@ mapMaybe f = List <<< map go <<< unwrap
463463
-- | Filter a list of optional values, keeping only the elements which contain
464464
-- | a value.
465465
catMaybes :: forall a. List (Maybe a) -> List a
466-
catMaybes = mapMaybe id
466+
catMaybes = mapMaybe identity
467467

468468
--------------------------------------------------------------------------------
469469
-- Sorting ---------------------------------------------------------------------
@@ -509,10 +509,11 @@ slice start end xs = take (end - start) (drop start xs)
509509
-- |
510510
-- | Running time: `O(n)` where `n` is the number of elements to take.
511511
take :: forall a. Int -> List a -> List a
512-
take n = List <<< map (go n) <<< unwrap
512+
take n = if n <= 0
513+
then const nil
514+
else List <<< map (go n) <<< unwrap
513515
where
514516
go :: Int -> Step a -> Step a
515-
go i _ | i <= 0 = Nil
516517
go _ Nil = Nil
517518
go n' (Cons x xs) = Cons x (take (n' - 1) xs)
518519

src/Data/List/Lazy/Types.purs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Data.FoldableWithIndex (class FoldableWithIndex, foldlWithIndex, foldrWit
1616
import Data.FunctorWithIndex (class FunctorWithIndex)
1717
import Data.Lazy (Lazy, defer, force)
1818
import Data.Maybe (Maybe(..))
19-
import Data.Monoid (class Monoid, mempty)
2019
import Data.Newtype (class Newtype, unwrap)
2120
import Data.NonEmpty (NonEmpty, (:|))
2221
import Data.NonEmpty as NE
@@ -25,6 +24,7 @@ import Data.Traversable (class Traversable, traverse, sequence)
2524
import Data.TraversableWithIndex (class TraversableWithIndex)
2625
import Data.Tuple (Tuple(..), snd)
2726
import Data.Unfoldable (class Unfoldable)
27+
import Data.Unfoldable1 (class Unfoldable1)
2828

2929
-- | A lazy linked list.
3030
newtype List a = List (Lazy (Step a))
@@ -141,6 +141,12 @@ instance foldableWithIndexList :: FoldableWithIndex Int List where
141141
snd <<< foldl (\(Tuple i b) a -> Tuple (i + 1) (f i b a)) (Tuple 0 acc)
142142
foldMapWithIndex f = foldlWithIndex (\i acc -> append acc <<< f i) mempty
143143

144+
instance unfoldable1List :: Unfoldable1 List where
145+
unfoldr1 = go where
146+
go f b = Z.defer \_ -> case f b of
147+
Tuple a (Just b') -> a : go f b'
148+
Tuple a Nothing -> a : nil
149+
144150
instance unfoldableList :: Unfoldable List where
145151
unfoldr = go where
146152
go f b = Z.defer \_ -> case f b of
@@ -151,7 +157,7 @@ instance traversableList :: Traversable List where
151157
traverse f =
152158
foldr (\a b -> cons <$> f a <*> b) (pure nil)
153159

154-
sequence = traverse id
160+
sequence = traverse identity
155161

156162
instance traversableWithIndexList :: TraversableWithIndex Int List where
157163
traverseWithIndex f =

src/Data/List/NonEmpty.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ catMaybes :: forall a. NonEmptyList (Maybe a) -> L.List a
210210
catMaybes = lift L.catMaybes
211211

212212
concat :: forall a. NonEmptyList (NonEmptyList a) -> NonEmptyList a
213-
concat = (_ >>= id)
213+
concat = (_ >>= identity)
214214

215215
concatMap :: forall a b. (a -> NonEmptyList b) -> NonEmptyList a -> NonEmptyList b
216216
concatMap = flip bind

src/Data/List/Types.purs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import Data.Foldable (class Foldable, foldl, foldr, intercalate)
1515
import Data.FoldableWithIndex (class FoldableWithIndex, foldlWithIndex, foldrWithIndex)
1616
import Data.FunctorWithIndex (class FunctorWithIndex)
1717
import Data.Maybe (Maybe(..))
18-
import Data.Monoid (class Monoid, mempty)
1918
import Data.Newtype (class Newtype)
2019
import Data.NonEmpty (NonEmpty, (:|))
2120
import Data.NonEmpty as NE
@@ -26,6 +25,7 @@ import Data.Traversable (class Traversable, traverse)
2625
import Data.TraversableWithIndex (class TraversableWithIndex)
2726
import Data.Tuple (Tuple(..), snd)
2827
import Data.Unfoldable (class Unfoldable)
28+
import Data.Unfoldable1 (class Unfoldable1)
2929

3030
data List a = Nil | Cons a (List a)
3131

@@ -99,6 +99,13 @@ instance foldableWithIndexList :: FoldableWithIndex Int List where
9999
snd <<< foldl (\(Tuple i b) a -> Tuple (i + 1) (f i b a)) (Tuple 0 acc)
100100
foldMapWithIndex f = foldlWithIndex (\i acc -> append acc <<< f i) mempty
101101

102+
instance unfoldable1List :: Unfoldable1 List where
103+
unfoldr1 f b = go b Nil
104+
where
105+
go source memo = case f source of
106+
Tuple one (Just rest) -> go rest (one : memo)
107+
Tuple one Nothing -> foldl (flip (:)) Nil (one : memo)
108+
102109
instance unfoldableList :: Unfoldable List where
103110
unfoldr f b = go b Nil
104111
where
@@ -108,7 +115,7 @@ instance unfoldableList :: Unfoldable List where
108115

109116
instance traversableList :: Traversable List where
110117
traverse f = map (foldl (flip (:)) Nil) <<< foldl (\acc -> lift2 (flip (:)) acc <<< f) (pure Nil)
111-
sequence = traverse id
118+
sequence = traverse identity
112119

113120
instance traversableWithIndexList :: TraversableWithIndex Int List where
114121
traverseWithIndex f =
@@ -204,14 +211,10 @@ derive newtype instance foldableNonEmptyList :: Foldable NonEmptyList
204211

205212
derive newtype instance traversableNonEmptyList :: Traversable NonEmptyList
206213

207-
instance foldable1NonEmptyList :: Foldable1 NonEmptyList where
208-
fold1 (NonEmptyList (a :| as)) =
209-
foldl append a as
210-
foldMap1 f (NonEmptyList (a :| as)) =
211-
foldl (\acc -> append acc <<< f) (f a) as
214+
derive newtype instance foldable1NonEmptyList :: Foldable1 NonEmptyList
212215

213216
instance traversable1NonEmptyList :: Traversable1 NonEmptyList where
214217
traverse1 f (NonEmptyList (a :| as)) =
215218
foldl (\acc -> lift2 (flip nelCons) acc <<< f) (pure <$> f a) as
216219
<#> case _ of NonEmptyList (x :| xs) → foldl (flip nelCons) (pure x) xs
217-
sequence1 = traverse1 id
220+
sequence1 = traverse1 identity

src/Data/List/ZipList.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ module Data.List.ZipList
66
) where
77

88
import Prelude
9+
import Prim.TypeError (class Fail, Text)
910
import Control.Alt (class Alt)
1011
import Control.Alternative (class Alternative)
1112
import Control.Plus (class Plus)
1213
import Data.Foldable (class Foldable)
1314
import Data.List.Lazy (List, repeat, zipWith)
14-
import Data.Monoid (class Monoid, mempty)
1515
import Data.Newtype (class Newtype)
1616
import Data.Traversable (class Traversable)
1717
import Partial.Unsafe (unsafeCrashWith)
@@ -54,12 +54,12 @@ instance plusZipList :: Plus ZipList where
5454
instance alternativeZipList :: Alternative ZipList
5555

5656
instance zipListIsNotBind
57-
:: Fail """
57+
:: Fail (Text """
5858
ZipList is not Bind. Any implementation would break the associativity law.
5959
6060
Possible alternatives:
6161
Data.List.List
6262
Data.List.Lazy.List
63-
"""
63+
""")
6464
=> Bind ZipList where
6565
bind = unsafeCrashWith "bind: unreachable"

test/Test/Data/List.purs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module Test.Data.List (testList) where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE, log)
75
import Data.Foldable (foldMap, foldl)
86
import Data.FoldableWithIndex (foldMapWithIndex, foldlWithIndex, foldrWithIndex)
97
import Data.List (List(..), (..), stripPrefix, Pattern(..), length, range, foldM, unzip, zip, zipWithA, zipWith, intersectBy, intersect, (\\), deleteBy, delete, unionBy, union, nubBy, nub, groupBy, group', group, partition, span, dropWhile, drop, dropEnd, takeWhile, take, takeEnd, sortBy, sort, catMaybes, mapMaybe, filterM, filter, concat, concatMap, reverse, alterAt, modifyAt, updateAt, deleteAt, insertAt, findLastIndex, findIndex, elemLastIndex, elemIndex, (!!), uncons, unsnoc, init, tail, last, head, insertBy, insert, snoc, null, singleton, fromFoldable, transpose, mapWithIndex, (:))
@@ -15,10 +13,13 @@ import Data.Traversable (traverse)
1513
import Data.TraversableWithIndex (traverseWithIndex)
1614
import Data.Tuple (Tuple(..))
1715
import Data.Unfoldable (replicate, replicateA, unfoldr)
16+
import Data.Unfoldable1 (unfoldr1)
17+
import Effect (Effect)
18+
import Effect.Console (log)
1819
import Partial.Unsafe (unsafePartial)
19-
import Test.Assert (ASSERT, assert)
20+
import Test.Assert (assert)
2021

21-
testList :: forall eff. Eff (assert :: ASSERT, console :: CONSOLE | eff) Unit
22+
testList :: Effect Unit
2223
testList = do
2324
let l = fromFoldable
2425

@@ -357,8 +358,11 @@ testList = do
357358
log "unfoldr should maintain order"
358359
assert $ (1..5) == unfoldr step 1
359360

361+
log "unfoldr1 should maintain order"
362+
assert $ (1..5) == unfoldr1 step1 1
363+
360364
log "map should maintain order"
361-
assert $ (1..5) == map id (1..5)
365+
assert $ (1..5) == map identity (1..5)
362366

363367
log "transpose"
364368
assert $ transpose (l [l [1,2,3], l[4,5,6], l [7,8,9]]) ==
@@ -388,11 +392,13 @@ testList = do
388392
log "append should be stack-safe"
389393
void $ pure $ xs <> xs
390394

391-
392395
step :: Int -> Maybe (Tuple Int Int)
393396
step 6 = Nothing
394397
step n = Just (Tuple n (n + 1))
395398

399+
step1 :: Int -> Tuple Int (Maybe Int)
400+
step1 n = Tuple n (if n >= 5 then Nothing else Just (n + 1))
401+
396402
nil :: List Int
397403
nil = Nil
398404

0 commit comments

Comments
 (0)