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 157b396..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": "^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-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": "^4.0.0", - "purescript-assert": "^3.0.0", - "purescript-console": "^3.0.0", - "purescript-math": "^2.0.0" + "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 f1deb35..6b258fe 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": "^11.0.0", - "purescript-psa": "^0.5.1", - "rimraf": "^2.6.1" + "pulp": "^12.2.0", + "purescript-psa": "^0.6.0", + "rimraf": "^2.6.2" } } diff --git a/src/Data/List.purs b/src/Data/List.purs index d2011c3..61a2106 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. @@ -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 --------------------------------------------------------- -------------------------------------------------------------------------------- diff --git a/src/Data/List/Lazy.purs b/src/Data/List/Lazy.purs index 8f9f5ef..67393f0 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 --------------------------------------------------------------------- @@ -509,10 +509,11 @@ 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 = if n <= 0 + then const nil + else List <<< map (go n) <<< unwrap 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) diff --git a/src/Data/List/Lazy/Types.purs b/src/Data/List/Lazy/Types.purs index a385494..1e1976a 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 @@ -25,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)) @@ -141,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 @@ -151,7 +157,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..fcebde8 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 @@ -26,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) @@ -99,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 @@ -108,7 +115,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 = @@ -204,14 +211,10 @@ 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)) = 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 265dbd3..920be44 100644 --- a/src/Data/List/ZipList.purs +++ b/src/Data/List/ZipList.purs @@ -6,12 +6,12 @@ module Data.List.ZipList ) where import Prelude +import Prim.TypeError (class Fail, Text) import Control.Alt (class Alt) 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) @@ -54,12 +54,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" diff --git a/test/Test/Data/List.purs b/test/Test/Data/List.purs index f2130f3..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 Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (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,10 +13,13 @@ 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, assert) +import Test.Assert (assert) -testList :: forall eff. Eff (assert :: ASSERT, console :: CONSOLE | eff) Unit +testList :: Effect Unit testList = do let l = fromFoldable @@ -357,8 +358,11 @@ 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 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]]) == @@ -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 4c155a4..a108215 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 Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (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,10 +14,14 @@ 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, assert) +import Test.Assert (assert) -testListLazy :: forall eff. Eff (assert :: ASSERT, console :: CONSOLE | eff) Unit +testListLazy :: Effect Unit testListLazy = do let l = fromFoldable @@ -270,6 +272,12 @@ 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 + 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" assert $ (takeWhile (_ /= 2) (l [1, 2, 3])) == l [1] assert $ (takeWhile (_ /= 3) (l [1, 2, 3])) == l [1, 2] @@ -396,9 +404,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 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