From 25dce0ee6aff6b4e95e24d90eb7d60eaaea7731a Mon Sep 17 00:00:00 2001 From: ibara1454 Date: Wed, 3 Jan 2018 17:22:51 +0900 Subject: [PATCH 01/14] Fix bug of Data.List.Lazy(take). --- src/Data/List/Lazy.purs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Data/List/Lazy.purs b/src/Data/List/Lazy.purs index 8f9f5ef..0dfb15d 100644 --- a/src/Data/List/Lazy.purs +++ b/src/Data/List/Lazy.purs @@ -509,10 +509,10 @@ slice start end xs = take (end - start) (drop start xs) -- | -- | Running time: `O(n)` where `n` is the number of elements to take. take :: forall a. Int -> List a -> List a -take n = List <<< map (go n) <<< unwrap +take n _ | n <= 0 = nil +take n xs = List <<< map (go n) <<< unwrap $ xs where go :: Int -> Step a -> Step a - go i _ | i <= 0 = Nil go _ Nil = Nil go n' (Cons x xs) = Cons x (take (n' - 1) xs) From 768708fac6fc07bf70d0a5731dc13987ad0eb735 Mon Sep 17 00:00:00 2001 From: ibara1454 Date: Thu, 4 Jan 2018 03:03:16 +0900 Subject: [PATCH 02/14] Resolve #138 From e1b0b94c3f5c2d7f3b7896398b1686d891c23207 Mon Sep 17 00:00:00 2001 From: ibara1454 Date: Sat, 20 Jan 2018 23:52:26 +0900 Subject: [PATCH 03/14] Rewrite with pointfree style instead --- src/Data/List/Lazy.purs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Data/List/Lazy.purs b/src/Data/List/Lazy.purs index 0dfb15d..606983b 100644 --- a/src/Data/List/Lazy.purs +++ b/src/Data/List/Lazy.purs @@ -509,8 +509,9 @@ slice start end xs = take (end - start) (drop start xs) -- | -- | Running time: `O(n)` where `n` is the number of elements to take. take :: forall a. Int -> List a -> List a -take n _ | n <= 0 = nil -take n xs = List <<< map (go n) <<< unwrap $ xs +take n = if n <= 0 + then const nil + else List <<< map (go n) <<< unwrap where go :: Int -> Step a -> Step a go _ Nil = Nil From 803e5e05ab4379d212cd51bfc9fdd57837eaf744 Mon Sep 17 00:00:00 2001 From: ibara1454 Date: Sun, 21 Jan 2018 01:02:48 +0900 Subject: [PATCH 04/14] Add test case. `take` should evaluate exactly n items which we needed --- test/Test/Data/List/Lazy.purs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/Test/Data/List/Lazy.purs b/test/Test/Data/List/Lazy.purs index 4c155a4..130a4dd 100644 --- a/test/Test/Data/List/Lazy.purs +++ b/test/Test/Data/List/Lazy.purs @@ -270,6 +270,11 @@ testListLazy = do assert $ (take 2 (l [1, 2, 3])) == l [1, 2] assert $ (take 1 nil') == nil' + log "take should evaluate exactly n items which we needed" + assert let oops x = 0 : (oops x) + in (take 1 $ 1 : defer oops) == fromFoldable [1] + -- If `take` evaluate more than once, it would crash with a stack overflow + log "takeWhile should keep all values that match a predicate from the front of an list" assert $ (takeWhile (_ /= 2) (l [1, 2, 3])) == l [1] assert $ (takeWhile (_ /= 3) (l [1, 2, 3])) == l [1, 2] From 13adceae7ceaa42172378dd384c2991cd02ce830 Mon Sep 17 00:00:00 2001 From: ibara1454 Date: Sun, 21 Jan 2018 01:27:47 +0900 Subject: [PATCH 05/14] Replace fromFoldable with l --- test/Test/Data/List/Lazy.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Test/Data/List/Lazy.purs b/test/Test/Data/List/Lazy.purs index 130a4dd..39f80ab 100644 --- a/test/Test/Data/List/Lazy.purs +++ b/test/Test/Data/List/Lazy.purs @@ -272,7 +272,7 @@ testListLazy = do log "take should evaluate exactly n items which we needed" assert let oops x = 0 : (oops x) - in (take 1 $ 1 : defer oops) == fromFoldable [1] + in (take 1 $ 1 : defer oops) == l [1] -- If `take` evaluate more than once, it would crash with a stack overflow log "takeWhile should keep all values that match a predicate from the front of an list" From 8229f7e0ac176015c685ad2e901cbda7767e8240 Mon Sep 17 00:00:00 2001 From: ibara1454 Date: Sun, 21 Jan 2018 02:45:52 +0900 Subject: [PATCH 06/14] Rewrite test case * Remove parens * Remove `($)` by let xs = 1 : defer oops --- test/Test/Data/List/Lazy.purs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/Test/Data/List/Lazy.purs b/test/Test/Data/List/Lazy.purs index 39f80ab..43cd1e3 100644 --- a/test/Test/Data/List/Lazy.purs +++ b/test/Test/Data/List/Lazy.purs @@ -271,8 +271,9 @@ testListLazy = do assert $ (take 1 nil') == nil' log "take should evaluate exactly n items which we needed" - assert let oops x = 0 : (oops x) - in (take 1 $ 1 : defer oops) == l [1] + assert let oops x = 0 : oops x + xs = 1 : defer oops + in take 1 xs == l [1] -- If `take` evaluate more than once, it would crash with a stack overflow log "takeWhile should keep all values that match a predicate from the front of an list" From c61596a8674b33213041f900e8516b5c3219e8da Mon Sep 17 00:00:00 2001 From: Liam Goodacre Date: Sun, 11 Mar 2018 15:04:18 +0000 Subject: [PATCH 07/14] Bump dev dependencies --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f1deb35..674c160 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "test": "pulp test" }, "devDependencies": { - "pulp": "^11.0.0", - "purescript-psa": "^0.5.1", + "pulp": "^12.0.1", + "purescript-psa": "^0.6.0", "rimraf": "^2.6.1" } } From 9aa81efcbf9bf3a07cc10915ab1c80261c833a00 Mon Sep 17 00:00:00 2001 From: Liam Goodacre Date: Sat, 3 Mar 2018 13:56:29 +0000 Subject: [PATCH 08/14] Import Prim.TypeError.Fail --- src/Data/List/ZipList.purs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Data/List/ZipList.purs b/src/Data/List/ZipList.purs index 265dbd3..556af0d 100644 --- a/src/Data/List/ZipList.purs +++ b/src/Data/List/ZipList.purs @@ -6,6 +6,7 @@ module Data.List.ZipList ) where import Prelude +import Prim.TypeError (class Fail) import Control.Alt (class Alt) import Control.Alternative (class Alternative) import Control.Plus (class Plus) From 53425f1e990df1c80971a5144c280bddb27f7cc6 Mon Sep 17 00:00:00 2001 From: Matthew Leon Date: Fri, 26 Jan 2018 23:17:46 -0500 Subject: [PATCH 09/14] NonEmptyList: newtype derive Foldable1 --- bower.json | 2 +- src/Data/List/Types.purs | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index 157b396..77ac585 100644 --- a/bower.json +++ b/bower.json @@ -21,7 +21,7 @@ ], "dependencies": { "purescript-lazy": "^3.0.0", - "purescript-nonempty": "^4.0.0", + "purescript-nonempty": "^4.2.0", "purescript-tailrec": "^3.3.0", "purescript-unfoldable": "^3.0.0", "purescript-partial": "^1.0.0", diff --git a/src/Data/List/Types.purs b/src/Data/List/Types.purs index aba3c06..57d138c 100644 --- a/src/Data/List/Types.purs +++ b/src/Data/List/Types.purs @@ -204,11 +204,7 @@ derive newtype instance foldableNonEmptyList :: Foldable NonEmptyList derive newtype instance traversableNonEmptyList :: Traversable NonEmptyList -instance foldable1NonEmptyList :: Foldable1 NonEmptyList where - fold1 (NonEmptyList (a :| as)) = - foldl append a as - foldMap1 f (NonEmptyList (a :| as)) = - foldl (\acc -> append acc <<< f) (f a) as +derive newtype instance foldable1NonEmptyList :: Foldable1 NonEmptyList instance traversable1NonEmptyList :: Traversable1 NonEmptyList where traverse1 f (NonEmptyList (a :| as)) = From 2bb1c953d882515d83d3cbb3fd8c485d2ad50688 Mon Sep 17 00:00:00 2001 From: Liam Goodacre Date: Wed, 11 Apr 2018 00:37:10 +0100 Subject: [PATCH 10/14] Update use of `Fail` to use `Text :: Symbol -> Doc` --- src/Data/List/ZipList.purs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Data/List/ZipList.purs b/src/Data/List/ZipList.purs index 556af0d..bdaf632 100644 --- a/src/Data/List/ZipList.purs +++ b/src/Data/List/ZipList.purs @@ -6,7 +6,7 @@ module Data.List.ZipList ) where import Prelude -import Prim.TypeError (class Fail) +import Prim.TypeError (class Fail, Text) import Control.Alt (class Alt) import Control.Alternative (class Alternative) import Control.Plus (class Plus) @@ -55,12 +55,12 @@ instance plusZipList :: Plus ZipList where instance alternativeZipList :: Alternative ZipList instance zipListIsNotBind - :: Fail """ + :: Fail (Text """ ZipList is not Bind. Any implementation would break the associativity law. Possible alternatives: Data.List.List Data.List.Lazy.List - """ + """) => Bind ZipList where bind = unsafeCrashWith "bind: unreachable" From e84d02edf1910a1c652bf8ffd804c770ec73adfb Mon Sep 17 00:00:00 2001 From: Liam Goodacre Date: Thu, 19 Apr 2018 12:10:13 +0100 Subject: [PATCH 11/14] Bump deps for compiler/0.12 --- bower.json | 20 ++++++++++---------- package.json | 4 ++-- src/Data/List.purs | 4 ++-- src/Data/List/Lazy.purs | 4 ++-- src/Data/List/Lazy/Types.purs | 3 +-- src/Data/List/NonEmpty.purs | 2 +- src/Data/List/Types.purs | 5 ++--- src/Data/List/ZipList.purs | 1 - test/Test/Data/List.purs | 10 +++++----- test/Test/Data/List/Lazy.purs | 8 ++++---- test/Test/Data/List/NonEmpty.purs | 11 +++++------ test/Test/Data/List/Partial.purs | 8 ++++---- test/Test/Data/List/ZipList.purs | 10 +++++----- test/Test/Main.purs | 6 ++---- 14 files changed, 45 insertions(+), 51 deletions(-) diff --git a/bower.json b/bower.json index 157b396..9e93f0e 100644 --- a/bower.json +++ b/bower.json @@ -20,17 +20,17 @@ "package.json" ], "dependencies": { - "purescript-lazy": "^3.0.0", - "purescript-nonempty": "^4.0.0", - "purescript-tailrec": "^3.3.0", - "purescript-unfoldable": "^3.0.0", - "purescript-partial": "^1.0.0", - "purescript-foldable-traversable": "^3.4.0" + "purescript-lazy": "#compiler/0.12", + "purescript-nonempty": "#compiler/0.12", + "purescript-tailrec": "#compiler/0.12", + "purescript-unfoldable": "#compiler/0.12", + "purescript-partial": "#compiler/0.12", + "purescript-foldable-traversable": "#compiler/0.12" }, "devDependencies": { - "purescript-arrays": "^4.0.0", - "purescript-assert": "^3.0.0", - "purescript-console": "^3.0.0", - "purescript-math": "^2.0.0" + "purescript-arrays": "#compiler/0.12", + "purescript-assert": "#compiler/0.12", + "purescript-console": "#compiler/0.12", + "purescript-math": "#compiler/0.12" } } diff --git a/package.json b/package.json index 674c160..40cbffe 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,11 @@ "scripts": { "clean": "rimraf output && rimraf .pulp-cache", "build": "pulp build -- --censor-lib --strict", - "test": "pulp test" + "test": "pulp test --check-main-type Effect.Effect" }, "devDependencies": { "pulp": "^12.0.1", "purescript-psa": "^0.6.0", - "rimraf": "^2.6.1" + "rimraf": "^2.6.2" } } diff --git a/src/Data/List.purs b/src/Data/List.purs index d2011c3..dffed21 100644 --- a/src/Data/List.purs +++ b/src/Data/List.purs @@ -372,7 +372,7 @@ reverse = go Nil -- | -- | Running time: `O(n)`, where `n` is the total number of elements. concat :: forall a. List (List a) -> List a -concat = (_ >>= id) +concat = (_ >>= identity) -- | Apply a function to each element in a list, and flatten the results -- | into a single, new list. @@ -423,7 +423,7 @@ mapMaybe f = go Nil -- | Filter a list of optional values, keeping only the elements which contain -- | a value. catMaybes :: forall a. List (Maybe a) -> List a -catMaybes = mapMaybe id +catMaybes = mapMaybe identity -- | Apply a function to each element and its index in a list starting at 0. diff --git a/src/Data/List/Lazy.purs b/src/Data/List/Lazy.purs index 8f9f5ef..34e3d13 100644 --- a/src/Data/List/Lazy.purs +++ b/src/Data/List/Lazy.purs @@ -409,7 +409,7 @@ reverse xs = Z.defer \_ -> foldl (flip cons) nil xs -- | -- | Running time: `O(n)`, where `n` is the total number of elements. concat :: forall a. List (List a) -> List a -concat = (_ >>= id) +concat = (_ >>= identity) -- | Apply a function to each element in a list, and flatten the results -- | into a single, new list. @@ -463,7 +463,7 @@ mapMaybe f = List <<< map go <<< unwrap -- | Filter a list of optional values, keeping only the elements which contain -- | a value. catMaybes :: forall a. List (Maybe a) -> List a -catMaybes = mapMaybe id +catMaybes = mapMaybe identity -------------------------------------------------------------------------------- -- Sorting --------------------------------------------------------------------- diff --git a/src/Data/List/Lazy/Types.purs b/src/Data/List/Lazy/Types.purs index a385494..922bb7d 100644 --- a/src/Data/List/Lazy/Types.purs +++ b/src/Data/List/Lazy/Types.purs @@ -16,7 +16,6 @@ import Data.FoldableWithIndex (class FoldableWithIndex, foldlWithIndex, foldrWit import Data.FunctorWithIndex (class FunctorWithIndex) import Data.Lazy (Lazy, defer, force) import Data.Maybe (Maybe(..)) -import Data.Monoid (class Monoid, mempty) import Data.Newtype (class Newtype, unwrap) import Data.NonEmpty (NonEmpty, (:|)) import Data.NonEmpty as NE @@ -151,7 +150,7 @@ instance traversableList :: Traversable List where traverse f = foldr (\a b -> cons <$> f a <*> b) (pure nil) - sequence = traverse id + sequence = traverse identity instance traversableWithIndexList :: TraversableWithIndex Int List where traverseWithIndex f = diff --git a/src/Data/List/NonEmpty.purs b/src/Data/List/NonEmpty.purs index 5896755..c114bb7 100644 --- a/src/Data/List/NonEmpty.purs +++ b/src/Data/List/NonEmpty.purs @@ -210,7 +210,7 @@ catMaybes :: forall a. NonEmptyList (Maybe a) -> L.List a catMaybes = lift L.catMaybes concat :: forall a. NonEmptyList (NonEmptyList a) -> NonEmptyList a -concat = (_ >>= id) +concat = (_ >>= identity) concatMap :: forall a b. (a -> NonEmptyList b) -> NonEmptyList a -> NonEmptyList b concatMap = flip bind diff --git a/src/Data/List/Types.purs b/src/Data/List/Types.purs index aba3c06..b29d700 100644 --- a/src/Data/List/Types.purs +++ b/src/Data/List/Types.purs @@ -15,7 +15,6 @@ import Data.Foldable (class Foldable, foldl, foldr, intercalate) import Data.FoldableWithIndex (class FoldableWithIndex, foldlWithIndex, foldrWithIndex) import Data.FunctorWithIndex (class FunctorWithIndex) import Data.Maybe (Maybe(..)) -import Data.Monoid (class Monoid, mempty) import Data.Newtype (class Newtype) import Data.NonEmpty (NonEmpty, (:|)) import Data.NonEmpty as NE @@ -108,7 +107,7 @@ instance unfoldableList :: Unfoldable List where instance traversableList :: Traversable List where traverse f = map (foldl (flip (:)) Nil) <<< foldl (\acc -> lift2 (flip (:)) acc <<< f) (pure Nil) - sequence = traverse id + sequence = traverse identity instance traversableWithIndexList :: TraversableWithIndex Int List where traverseWithIndex f = @@ -214,4 +213,4 @@ instance traversable1NonEmptyList :: Traversable1 NonEmptyList where traverse1 f (NonEmptyList (a :| as)) = foldl (\acc -> lift2 (flip nelCons) acc <<< f) (pure <$> f a) as <#> case _ of NonEmptyList (x :| xs) → foldl (flip nelCons) (pure x) xs - sequence1 = traverse1 id + sequence1 = traverse1 identity diff --git a/src/Data/List/ZipList.purs b/src/Data/List/ZipList.purs index bdaf632..920be44 100644 --- a/src/Data/List/ZipList.purs +++ b/src/Data/List/ZipList.purs @@ -12,7 +12,6 @@ import Control.Alternative (class Alternative) import Control.Plus (class Plus) import Data.Foldable (class Foldable) import Data.List.Lazy (List, repeat, zipWith) -import Data.Monoid (class Monoid, mempty) import Data.Newtype (class Newtype) import Data.Traversable (class Traversable) import Partial.Unsafe (unsafeCrashWith) diff --git a/test/Test/Data/List.purs b/test/Test/Data/List.purs index f2130f3..0e66de4 100644 --- a/test/Test/Data/List.purs +++ b/test/Test/Data/List.purs @@ -2,8 +2,8 @@ module Test.Data.List (testList) where import Prelude -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (CONSOLE, log) +import Effect (Effect) +import Effect.Console (log) import Data.Foldable (foldMap, foldl) import Data.FoldableWithIndex (foldMapWithIndex, foldlWithIndex, foldrWithIndex) 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, (:)) @@ -16,9 +16,9 @@ import Data.TraversableWithIndex (traverseWithIndex) import Data.Tuple (Tuple(..)) import Data.Unfoldable (replicate, replicateA, unfoldr) import Partial.Unsafe (unsafePartial) -import Test.Assert (ASSERT, assert) +import Test.Assert (assert) -testList :: forall eff. Eff (assert :: ASSERT, console :: CONSOLE | eff) Unit +testList :: Effect Unit testList = do let l = fromFoldable @@ -358,7 +358,7 @@ testList = do assert $ (1..5) == unfoldr step 1 log "map should maintain order" - assert $ (1..5) == map id (1..5) + assert $ (1..5) == map identity (1..5) log "transpose" assert $ transpose (l [l [1,2,3], l[4,5,6], l [7,8,9]]) == diff --git a/test/Test/Data/List/Lazy.purs b/test/Test/Data/List/Lazy.purs index 4c155a4..b7d0127 100644 --- a/test/Test/Data/List/Lazy.purs +++ b/test/Test/Data/List/Lazy.purs @@ -3,8 +3,8 @@ module Test.Data.List.Lazy (testListLazy) where import Prelude import Control.Lazy (defer) -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (CONSOLE, log) +import Effect (Effect) +import Effect.Console (log) import Data.FoldableWithIndex (foldMapWithIndex, foldlWithIndex, foldrWithIndex) import Data.FunctorWithIndex (mapWithIndex) import Data.Lazy as Z @@ -17,9 +17,9 @@ import Data.Traversable (traverse) import Data.TraversableWithIndex (traverseWithIndex) import Data.Tuple (Tuple(..)) import Partial.Unsafe (unsafePartial) -import Test.Assert (ASSERT, assert) +import Test.Assert (assert) -testListLazy :: forall eff. Eff (assert :: ASSERT, console :: CONSOLE | eff) Unit +testListLazy :: Effect Unit testListLazy = do let l = fromFoldable diff --git a/test/Test/Data/List/NonEmpty.purs b/test/Test/Data/List/NonEmpty.purs index 81ba440..a82b9c0 100644 --- a/test/Test/Data/List/NonEmpty.purs +++ b/test/Test/Data/List/NonEmpty.purs @@ -2,8 +2,8 @@ module Test.Data.List.NonEmpty (testNonEmptyList) where import Prelude -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (CONSOLE, log) +import Effect (Effect) +import Effect.Console (log) import Data.Foldable (class Foldable, foldM, foldMap, foldl, length) import Data.List as L import Data.List.NonEmpty as NEL @@ -11,10 +11,9 @@ import Data.Maybe (Maybe(..)) import Data.Monoid.Additive (Additive(..)) import Data.NonEmpty ((:|)) import Data.Tuple (Tuple(..)) -import Test.Assert (ASSERT, assert) +import Test.Assert (assert) -testNonEmptyList :: - forall eff. Eff (assert :: ASSERT, console :: CONSOLE | eff) Unit +testNonEmptyList :: Effect Unit testNonEmptyList = do let nel :: ∀ f a. Foldable f => a -> f a -> NEL.NonEmptyList a @@ -223,7 +222,7 @@ testNonEmptyList = do assert $ foldMap show (nel 1 (L.range 2 5)) == "12345" log "map should maintain order" - assert $ nel 0 (L.range 1 5) == map id (nel 0 (L.range 1 5)) + assert $ nel 0 (L.range 1 5) == map identity (nel 0 (L.range 1 5)) log "traverse1 should be stack-safe" let xs = nel 0 (L.range 1 100000) diff --git a/test/Test/Data/List/Partial.purs b/test/Test/Data/List/Partial.purs index 9780577..cf5ea69 100644 --- a/test/Test/Data/List/Partial.purs +++ b/test/Test/Data/List/Partial.purs @@ -2,17 +2,17 @@ module Test.Data.List.Partial (testListPartial) where import Prelude -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (CONSOLE, log) +import Effect (Effect) +import Effect.Console (log) import Data.List (List(..), fromFoldable) import Data.List.Partial (init, tail, last, head) import Partial.Unsafe (unsafePartial) -import Test.Assert (ASSERT, assert, assertThrows) +import Test.Assert (assert, assertThrows) -testListPartial :: forall eff. Eff (assert :: ASSERT, console :: CONSOLE | eff) Unit +testListPartial :: Effect Unit testListPartial = do let l = fromFoldable diff --git a/test/Test/Data/List/ZipList.purs b/test/Test/Data/List/ZipList.purs index 1c1a6f1..366c53c 100644 --- a/test/Test/Data/List/ZipList.purs +++ b/test/Test/Data/List/ZipList.purs @@ -2,23 +2,23 @@ module Test.Data.List.ZipList (testZipList) where import Prelude -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (CONSOLE, log) +import Effect (Effect) +import Effect.Console (log) import Data.Array as Array import Data.List.Lazy as LazyList import Data.List.ZipList (ZipList(..)) -import Test.Assert (ASSERT, assert) +import Test.Assert (assert) -testZipList :: forall eff. Eff (assert :: ASSERT, console :: CONSOLE | eff) Unit +testZipList :: Effect Unit testZipList = do log "ZipList Applicative instance should be zippy" testZipWith (+) [1,2,3] [4,5,6] testZipWith (*) [1,2,3] [4,5,6] testZipWith const [1,2,3] [4,5,6] -testZipWith :: forall a b c eff. Eq c => (a -> b -> c) -> Array a -> Array b -> Eff (assert :: ASSERT, console :: CONSOLE | eff) Unit +testZipWith :: forall a b c. Eq c => (a -> b -> c) -> Array a -> Array b -> Effect Unit testZipWith f xs ys = assert $ (f <$> l xs <*> l ys) == l (Array.zipWith f xs ys) diff --git a/test/Test/Main.purs b/test/Test/Main.purs index ea999be..096e807 100644 --- a/test/Test/Main.purs +++ b/test/Test/Main.purs @@ -2,17 +2,15 @@ module Test.Main where import Prelude -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (CONSOLE) +import Effect (Effect) -import Test.Assert (ASSERT) import Test.Data.List (testList) import Test.Data.List.Lazy (testListLazy) import Test.Data.List.Partial (testListPartial) import Test.Data.List.ZipList (testZipList) import Test.Data.List.NonEmpty (testNonEmptyList) -main :: forall eff. Eff (assert :: ASSERT, console :: CONSOLE | eff) Unit +main :: Effect Unit main = do testList testListLazy From 9ed99f13ae2a6315bd1bd1c006e4e5a474daddf3 Mon Sep 17 00:00:00 2001 From: Cole Haus Date: Mon, 7 May 2018 14:28:46 -0700 Subject: [PATCH 12/14] Add `tails` --- src/Data/List.purs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Data/List.purs b/src/Data/List.purs index d2011c3..f48bc25 100644 --- a/src/Data/List.purs +++ b/src/Data/List.purs @@ -617,6 +617,16 @@ partition p xs = foldr select { no: Nil, yes: Nil } xs then { no, yes: x : yes } else { no: x : no, yes } +-- | Returns all final segments of the argument, longest first. For example, +-- | +-- | ```purescript +-- | tails (1 : 2 : 3 : Nil) == ((1 : 2 : 3 : Nil) : (2 : 3 : Nil) : (3 : Nil) : (Nil) : Nil) +-- | ``` +-- | Running time: `O(n)` +tails :: forall a. List a -> List (List a) +tails Nil = singleton Nil +tails list@(Cons _ tl)= list : tails tl + -------------------------------------------------------------------------------- -- Set-like operations --------------------------------------------------------- -------------------------------------------------------------------------------- From d44e56825a69e7f68339eee0520e25edb78811d4 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sat, 19 May 2018 01:40:07 +0100 Subject: [PATCH 13/14] Add Unfoldable1 instances for Unfoldables --- src/Data/List/Lazy/Types.purs | 7 +++++++ src/Data/List/Types.purs | 8 ++++++++ test/Test/Data/List.purs | 12 +++++++++--- test/Test/Data/List/Lazy.purs | 25 ++++++++++++++++++++++--- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/Data/List/Lazy/Types.purs b/src/Data/List/Lazy/Types.purs index 922bb7d..1e1976a 100644 --- a/src/Data/List/Lazy/Types.purs +++ b/src/Data/List/Lazy/Types.purs @@ -24,6 +24,7 @@ import Data.Traversable (class Traversable, traverse, sequence) import Data.TraversableWithIndex (class TraversableWithIndex) import Data.Tuple (Tuple(..), snd) import Data.Unfoldable (class Unfoldable) +import Data.Unfoldable1 (class Unfoldable1) -- | A lazy linked list. newtype List a = List (Lazy (Step a)) @@ -140,6 +141,12 @@ instance foldableWithIndexList :: FoldableWithIndex Int List where snd <<< foldl (\(Tuple i b) a -> Tuple (i + 1) (f i b a)) (Tuple 0 acc) foldMapWithIndex f = foldlWithIndex (\i acc -> append acc <<< f i) mempty +instance unfoldable1List :: Unfoldable1 List where + unfoldr1 = go where + go f b = Z.defer \_ -> case f b of + Tuple a (Just b') -> a : go f b' + Tuple a Nothing -> a : nil + instance unfoldableList :: Unfoldable List where unfoldr = go where go f b = Z.defer \_ -> case f b of diff --git a/src/Data/List/Types.purs b/src/Data/List/Types.purs index b29d700..c52d62a 100644 --- a/src/Data/List/Types.purs +++ b/src/Data/List/Types.purs @@ -25,6 +25,7 @@ import Data.Traversable (class Traversable, traverse) import Data.TraversableWithIndex (class TraversableWithIndex) import Data.Tuple (Tuple(..), snd) import Data.Unfoldable (class Unfoldable) +import Data.Unfoldable1 (class Unfoldable1) data List a = Nil | Cons a (List a) @@ -98,6 +99,13 @@ instance foldableWithIndexList :: FoldableWithIndex Int List where snd <<< foldl (\(Tuple i b) a -> Tuple (i + 1) (f i b a)) (Tuple 0 acc) foldMapWithIndex f = foldlWithIndex (\i acc -> append acc <<< f i) mempty +instance unfoldable1List :: Unfoldable1 List where + unfoldr1 f b = go b Nil + where + go source memo = case f source of + Tuple one (Just rest) -> go rest (one : memo) + Tuple one Nothing -> foldl (flip (:)) Nil (one : memo) + instance unfoldableList :: Unfoldable List where unfoldr f b = go b Nil where diff --git a/test/Test/Data/List.purs b/test/Test/Data/List.purs index 0e66de4..44966b3 100644 --- a/test/Test/Data/List.purs +++ b/test/Test/Data/List.purs @@ -2,8 +2,6 @@ module Test.Data.List (testList) where import Prelude -import Effect (Effect) -import Effect.Console (log) import Data.Foldable (foldMap, foldl) import Data.FoldableWithIndex (foldMapWithIndex, foldlWithIndex, foldrWithIndex) 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,6 +13,9 @@ import Data.Traversable (traverse) import Data.TraversableWithIndex (traverseWithIndex) import Data.Tuple (Tuple(..)) import Data.Unfoldable (replicate, replicateA, unfoldr) +import Data.Unfoldable1 (unfoldr1) +import Effect (Effect) +import Effect.Console (log) import Partial.Unsafe (unsafePartial) import Test.Assert (assert) @@ -357,6 +358,9 @@ testList = do log "unfoldr should maintain order" assert $ (1..5) == unfoldr step 1 + log "unfoldr1 should maintain order" + assert $ (1..5) == unfoldr1 step1 1 + log "map should maintain order" assert $ (1..5) == map identity (1..5) @@ -388,11 +392,13 @@ testList = do log "append should be stack-safe" void $ pure $ xs <> xs - step :: Int -> Maybe (Tuple Int Int) step 6 = Nothing step n = Just (Tuple n (n + 1)) +step1 :: Int -> Tuple Int (Maybe Int) +step1 n = Tuple n (if n >= 5 then Nothing else Just (n + 1)) + nil :: List Int nil = Nil diff --git a/test/Test/Data/List/Lazy.purs b/test/Test/Data/List/Lazy.purs index b7d0127..cf7da8f 100644 --- a/test/Test/Data/List/Lazy.purs +++ b/test/Test/Data/List/Lazy.purs @@ -3,12 +3,10 @@ module Test.Data.List.Lazy (testListLazy) where import Prelude import Control.Lazy (defer) -import Effect (Effect) -import Effect.Console (log) import Data.FoldableWithIndex (foldMapWithIndex, foldlWithIndex, foldrWithIndex) import Data.FunctorWithIndex (mapWithIndex) import Data.Lazy as Z -import Data.List.Lazy (List, nil, stripPrefix, Pattern(..), cons, foldl, foldr, foldMap, singleton, transpose, take, iterate, filter, uncons, foldM, foldrLazy, range, unzip, zip, length, zipWithA, replicate, repeat, zipWith, intersectBy, intersect, deleteBy, delete, unionBy, union, nubBy, nub, groupBy, group, partition, span, dropWhile, drop, takeWhile, slice, catMaybes, mapMaybe, filterM, concat, concatMap, reverse, alterAt, modifyAt, updateAt, deleteAt, insertAt, findLastIndex, findIndex, elemLastIndex, elemIndex, init, tail, last, head, insertBy, insert, snoc, null, replicateM, fromFoldable, (:), (\\), (!!)) +import Data.List.Lazy (List, Pattern(..), alterAt, catMaybes, concat, concatMap, cons, delete, deleteAt, deleteBy, drop, dropWhile, elemIndex, elemLastIndex, filter, filterM, findIndex, findLastIndex, foldM, foldMap, foldl, foldr, foldrLazy, fromFoldable, group, groupBy, head, init, insert, insertAt, insertBy, intersect, intersectBy, iterate, last, length, mapMaybe, modifyAt, nil, nub, nubBy, null, partition, range, repeat, replicate, replicateM, reverse, singleton, slice, snoc, span, stripPrefix, tail, take, takeWhile, transpose, uncons, union, unionBy, unzip, updateAt, zip, zipWith, zipWithA, (!!), (..), (:), (\\)) import Data.List.Lazy.NonEmpty as NEL import Data.Maybe (Maybe(..), isNothing, fromJust) import Data.Monoid.Additive (Additive(..)) @@ -16,6 +14,10 @@ import Data.NonEmpty ((:|)) import Data.Traversable (traverse) import Data.TraversableWithIndex (traverseWithIndex) import Data.Tuple (Tuple(..)) +import Data.Unfoldable (unfoldr) +import Data.Unfoldable1 (unfoldr1) +import Effect (Effect) +import Effect.Console (log) import Partial.Unsafe (unsafePartial) import Test.Assert (assert) @@ -396,9 +398,26 @@ testListLazy = do ((10:20:30:nil) : (11:31:nil) : (32:nil) : nil) log "transpose nil == nil" assert $ transpose nil == (nil :: List (List Int)) + log "transpose (singleton nil) == nil" assert $ transpose (singleton nil) == (nil :: List (List Int)) + log "unfoldr should maintain order" + assert $ (1..5) == unfoldr step 1 + + log "unfoldr1 should maintain order" + assert $ (1..5) == unfoldr1 step1 1 + + log "map should maintain order" + assert $ (1..5) == map identity (1..5) + +step :: Int -> Maybe (Tuple Int Int) +step 6 = Nothing +step n = Just (Tuple n (n + 1)) + +step1 :: Int -> Tuple Int (Maybe Int) +step1 n = Tuple n (if n >= 5 then Nothing else Just (n + 1)) + nil' :: List Int nil' = nil From ea868855db9e1282c5a36e52565adf890b91e150 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Wed, 23 May 2018 21:35:23 +0100 Subject: [PATCH 14/14] Update dependencies, license --- .gitignore | 1 + LICENSE | 70 +++++++++++++++------------------------------------- bower.json | 29 +++++++++++++--------- package.json | 2 +- 4 files changed, 39 insertions(+), 63 deletions(-) diff --git a/.gitignore b/.gitignore index 307f9c0..b215c44 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /bower_components/ /node_modules/ /output/ +package-lock.json diff --git a/LICENSE b/LICENSE index 6791433..311379c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,56 +1,26 @@ -Copyright (c) 2014 PureScript +Copyright 2018 PureScript -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. ------------------------------------------------------------------------------ - -The Glasgow Haskell Compiler License - -Copyright 2004, The University Court of the University of Glasgow. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -- Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -- Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. - -- Neither name of the University nor the names of its contributors may be -used to endorse or promote products derived from this software without +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF -GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -DAMAGE. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/bower.json b/bower.json index 9e93f0e..efc9e90 100644 --- a/bower.json +++ b/bower.json @@ -4,8 +4,7 @@ "authors": [ "Phil Freeman " ], - "description": "Linked lists", - "license": "MIT", + "license": "BSD-3-Clause", "repository": { "type": "git", "url": "git://github.com/purescript/purescript-lists.git" @@ -20,17 +19,23 @@ "package.json" ], "dependencies": { - "purescript-lazy": "#compiler/0.12", - "purescript-nonempty": "#compiler/0.12", - "purescript-tailrec": "#compiler/0.12", - "purescript-unfoldable": "#compiler/0.12", - "purescript-partial": "#compiler/0.12", - "purescript-foldable-traversable": "#compiler/0.12" + "purescript-bifunctors": "^4.0.0", + "purescript-control": "^4.0.0", + "purescript-foldable-traversable": "^4.0.0", + "purescript-lazy": "^4.0.0", + "purescript-maybe": "^4.0.0", + "purescript-newtype": "^3.0.0", + "purescript-nonempty": "^5.0.0", + "purescript-partial": "^2.0.0", + "purescript-prelude": "^4.0.0", + "purescript-tailrec": "^4.0.0", + "purescript-tuples": "^5.0.0", + "purescript-unfoldable": "^4.0.0" }, "devDependencies": { - "purescript-arrays": "#compiler/0.12", - "purescript-assert": "#compiler/0.12", - "purescript-console": "#compiler/0.12", - "purescript-math": "#compiler/0.12" + "purescript-arrays": "^5.0.0", + "purescript-assert": "^4.0.0", + "purescript-console": "^4.0.0", + "purescript-math": "^2.1.1" } } diff --git a/package.json b/package.json index 40cbffe..6b258fe 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "test": "pulp test --check-main-type Effect.Effect" }, "devDependencies": { - "pulp": "^12.0.1", + "pulp": "^12.2.0", "purescript-psa": "^0.6.0", "rimraf": "^2.6.2" }