From cefcfb0a010ce9ce80777b677c48db85cdb54641 Mon Sep 17 00:00:00 2001 From: telser Date: Sat, 13 Feb 2016 16:30:31 -0500 Subject: [PATCH 1/2] Fix warnings generated by purescript 0.8.0 --- src/Data/Array.purs | 41 +++++++++++++------------------------- src/Data/Array/Unsafe.purs | 2 +- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/Data/Array.purs b/src/Data/Array.purs index 0498a9ea..6510e785 100644 --- a/src/Data/Array.purs +++ b/src/Data/Array.purs @@ -89,7 +89,7 @@ module Data.Array , delete , deleteBy - , (\\) + , (\\), difference , intersect , intersectBy @@ -101,21 +101,17 @@ module Data.Array , foldM ) where -import Prelude +import Prelude (class Monad, class Applicative, class Eq, class Ord, Unit, Ordering(LT, EQ, GT), (>>=), return, eq, const, otherwise, ($), flip, (++), (==), not, (<<<), negate, compare, id, bind, pure, one, (-), zero, (+), (<*>), (<$>), (<)) -import Control.Alt (Alt, (<|>)) -import Control.Alternative (Alternative) -import Control.Lazy (Lazy, defer) -import Control.MonadPlus (MonadPlus) -import Control.Plus (Plus) +import Control.Alt ((<|>)) +import Control.Alternative (class Alternative) +import Control.Lazy (class Lazy, defer) import Data.Foldable (foldl) -import Data.Functor.Invariant (Invariant) import Data.Maybe (Maybe(..), maybe, isJust) -import Data.Monoid (Monoid) import Data.Traversable (sequence) import Data.Tuple (Tuple(..)) -import qualified Data.Maybe.Unsafe as U +import Data.Maybe.Unsafe as U -- | Create an array of one element singleton :: forall a. a -> Array a @@ -124,11 +120,8 @@ singleton a = [a] -- | Create an array containing a range of integers, including both endpoints. foreign import range :: Int -> Int -> Array Int -infix 8 .. - -- | An infix synonym for `range`. -(..) :: Int -> Int -> Array Int -(..) = range +infix 8 range as .. -- | Create an array with repeated instances of a value. foreign import replicate :: forall a. Int -> a -> Array a @@ -177,13 +170,10 @@ foreign import length :: forall a. Array a -> Int -- | Note, the running time of this function is `O(n)`. foreign import cons :: forall a. a -> Array a -> Array a -infixr 6 : - -- | An infix alias for `cons`. -- | -- | Note, the running time of this function is `O(n)`. -(:) :: forall a. a -> Array a -> Array a -(:) = cons +infixr 6 cons as : -- | Append an element to the end of an array, creating a new array. foreign import snoc :: forall a. Array a -> a -> Array a @@ -265,11 +255,8 @@ foreign import indexImpl :: forall a. (forall r. r -> Maybe r) -> Int -> Maybe a -infixl 8 !! - -- | An infix version of `index`. -(!!) :: forall a. Array a -> Int -> Maybe a -(!!) = index +infixl 8 index as !! -- | Find the index of the first element equal to the specified element. elemIndex :: forall a. (Eq a) => a -> Array a -> Maybe Int @@ -524,13 +511,13 @@ deleteBy :: forall a. (a -> a -> Boolean) -> a -> Array a -> Array a deleteBy _ _ [] = [] deleteBy eq x ys = maybe ys (\i -> U.fromJust $ deleteAt i ys) (findIndex (eq x) ys) -infix 5 \\ - -- | Delete the first occurrence of each element in the second array from the -- | first array, creating a new array. -(\\) :: forall a. (Eq a) => Array a -> Array a -> Array a -(\\) xs ys | null xs = [] - | otherwise = uncons' (const xs) (\y ys -> delete y xs \\ ys) ys +difference :: forall a. (Eq a) => Array a -> Array a -> Array a +difference xs ys | null xs = [] + | otherwise = uncons' (const xs) (\z zs -> delete z xs \\ zs) ys + +infix 5 difference as \\ -- | Calculate the intersection of two arrays, creating a new array. intersect :: forall a. (Eq a) => Array a -> Array a -> Array a diff --git a/src/Data/Array/Unsafe.purs b/src/Data/Array/Unsafe.purs index 34960971..dd0b6042 100644 --- a/src/Data/Array/Unsafe.purs +++ b/src/Data/Array/Unsafe.purs @@ -5,7 +5,7 @@ module Data.Array.Unsafe where -import Prelude +import Prelude ((-)) import Data.Array (length, slice) From 3ddd885f7b8edc2c84d85aa7ebedc892ab9bc23f Mon Sep 17 00:00:00 2001 From: telser Date: Sat, 5 Mar 2016 16:45:20 -0500 Subject: [PATCH 2/2] Updates for 0.8.2 and fix tests too --- src/Data/Array.purs | 6 ++--- test/Test/Data/Array.purs | 46 +++++++++++++++++++------------- test/Test/Data/Array/ST.purs | 20 +++++++++----- test/Test/Data/Array/Unsafe.purs | 16 ++++++++--- test/Test/Main.purs | 18 ++++++++++--- 5 files changed, 69 insertions(+), 37 deletions(-) diff --git a/src/Data/Array.purs b/src/Data/Array.purs index 6510e785..0b2d2cae 100644 --- a/src/Data/Array.purs +++ b/src/Data/Array.purs @@ -186,7 +186,7 @@ insert = insertBy compare -- | determine the ordering of elements. insertBy :: forall a. (a -> a -> Ordering) -> a -> Array a -> Array a insertBy cmp x ys = - let i = maybe 0 (+ 1) (findLastIndex (\y -> cmp x y == GT) ys) + let i = maybe 0 (_ + 1) (findLastIndex (\y -> cmp x y == GT) ys) in U.fromJust (insertAt i x ys) -------------------------------------------------------------------------------- @@ -260,11 +260,11 @@ infixl 8 index as !! -- | Find the index of the first element equal to the specified element. elemIndex :: forall a. (Eq a) => a -> Array a -> Maybe Int -elemIndex x = findIndex (== x) +elemIndex x = findIndex (_ == x) -- | Find the index of the last element equal to the specified element. elemLastIndex :: forall a. (Eq a) => a -> Array a -> Maybe Int -elemLastIndex x = findLastIndex (== x) +elemLastIndex x = findLastIndex (_ == x) -- | Find the first index for which a predicate holds. findIndex :: forall a. (a -> Boolean) -> Array a -> Maybe Int diff --git a/test/Test/Data/Array.purs b/test/Test/Data/Array.purs index 4d59e3c3..fca9ae7c 100644 --- a/test/Test/Data/Array.purs +++ b/test/Test/Data/Array.purs @@ -1,13 +1,21 @@ module Test.Data.Array (testArray) where -import Prelude -import Control.Monad.Eff.Console (log) -import Data.Array +import Prelude ((*), zero, (/=), mod, (==), ($), (+), bind, show, (<), (&&), compare, flip, const, (<<<), map, negate, unit, Unit) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Console (log, CONSOLE) +import Data.Array (range, foldM, unzip, zip, zipWithA, zipWith, intersectBy, intersect, (\\), deleteBy, delete, unionBy, union, nubBy, nub, groupBy, group', group, span, dropWhile, drop, takeWhile, take, sortBy, sort, catMaybes, mapMaybe, filterM, filter, concat, concatMap, reverse, alterAt, modifyAt, updateAt, deleteAt, insertAt, findLastIndex, findIndex, elemLastIndex, elemIndex, (!!), uncons, init, tail, last, head, insertBy, insert, snoc, (:), length, null, replicate, replicateM, singleton) import Data.Maybe (Maybe(..), isNothing) import Data.Maybe.Unsafe (fromJust) import Data.Tuple (Tuple(..)) -import Test.Assert (assert) - +import Test.Assert (assert, ASSERT) + +testArray :: forall t. + Eff + ( console :: CONSOLE + , assert :: ASSERT + | t + ) + Unit testArray = do log "singleton should construct an array with a single value" @@ -121,12 +129,12 @@ testArray = do assert $ (elemLastIndex 4 [1, 2, 1]) == Nothing log "findIndex should return the index of an item that a predicate returns true for in an array" - assert $ (findIndex (/= 1) [1, 2, 1]) == Just 1 - assert $ (findIndex (== 3) [1, 2, 1]) == Nothing + assert $ (findIndex (_ /= 1) [1, 2, 1]) == Just 1 + assert $ (findIndex (_ == 3) [1, 2, 1]) == Nothing log "findLastIndex should return the last index of an item in an array" - assert $ (findLastIndex (/= 1) [2, 1, 2]) == Just 2 - assert $ (findLastIndex (== 3) [2, 1, 2]) == Nothing + assert $ (findLastIndex (_ /= 1) [2, 1, 2]) == Just 2 + assert $ (findLastIndex (_ == 3) [2, 1, 2]) == Nothing log "insertAt should add an item at the specified index" assert $ (insertAt 0 1 [2, 3]) == Just [1, 2, 3] @@ -151,11 +159,11 @@ testArray = do assert $ (updateAt 1 9 nil) == Nothing log "modifyAt should update an item at the specified index" - assert $ (modifyAt 0 (+ 1) [1, 2, 3]) == Just [2, 2, 3] - assert $ (modifyAt 1 (+ 1) [1, 2, 3]) == Just [1, 3, 3] + assert $ (modifyAt 0 (_ + 1) [1, 2, 3]) == Just [2, 2, 3] + assert $ (modifyAt 1 (_ + 1) [1, 2, 3]) == Just [1, 3, 3] log "modifyAt should return Nothing if the index is out of range" - assert $ (modifyAt 1 (+ 1) nil) == Nothing + assert $ (modifyAt 1 (_ + 1) nil) == Nothing log "alterAt should update an item at the specified index when the function returns Just" assert $ (alterAt 0 (Just <<< (+ 1)) [1, 2, 3]) == Just [2, 2, 3] @@ -205,9 +213,9 @@ testArray = do assert $ (take 1 nil) == nil log "takeWhile should keep all values that match a predicate from the front of an array" - assert $ (takeWhile (/= 2) [1, 2, 3]) == [1] - assert $ (takeWhile (/= 3) [1, 2, 3]) == [1, 2] - assert $ (takeWhile (/= 1) nil) == nil + assert $ (takeWhile (_ /= 2) [1, 2, 3]) == [1] + assert $ (takeWhile (_ /= 3) [1, 2, 3]) == [1, 2] + assert $ (takeWhile (_ /= 1) nil) == nil log "drop should remove the specified number of items from the front of an array" assert $ (drop 1 [1, 2, 3]) == [2, 3] @@ -215,12 +223,12 @@ testArray = do assert $ (drop 1 nil) == nil log "dropWhile should remove all values that match a predicate from the front of an array" - assert $ (dropWhile (/= 1) [1, 2, 3]) == [1, 2, 3] - assert $ (dropWhile (/= 2) [1, 2, 3]) == [2, 3] - assert $ (dropWhile (/= 1) nil) == nil + assert $ (dropWhile (_ /= 1) [1, 2, 3]) == [1, 2, 3] + assert $ (dropWhile (_ /= 2) [1, 2, 3]) == [2, 3] + assert $ (dropWhile (_ /= 1) nil) == nil log "span should split an array in two based on a predicate" - let spanResult = span (< 4) [1, 2, 3, 4, 5, 6, 7] + let spanResult = span (_ < 4) [1, 2, 3, 4, 5, 6, 7] assert $ spanResult.init == [1, 2, 3] assert $ spanResult.rest == [4, 5, 6, 7] diff --git a/test/Test/Data/Array/ST.purs b/test/Test/Data/Array/ST.purs index 2bebfcdb..bb6ac67a 100644 --- a/test/Test/Data/Array/ST.purs +++ b/test/Test/Data/Array/ST.purs @@ -1,15 +1,21 @@ module Test.Data.Array.ST (testArrayST) where -import Prelude -import Control.Monad.Eff.Console (log, print) -import Control.Monad.Eff (runPure) +import Prelude (bind, (+), (*), (==), ($), return, negate, not, Unit) +import Control.Monad.Eff.Console (log, CONSOLE) +import Control.Monad.Eff (runPure, Eff) import Control.Monad.ST (runST) -import Data.Array () -import Data.Array.ST +import Data.Array.ST (toAssocArray, thaw, spliceSTArray, runSTArray, pokeSTArray, emptySTArray, peekSTArray, pushAllSTArray, pushSTArray, freeze) import Data.Foldable (all) import Data.Maybe (Maybe(..), isNothing) -import Test.Assert (assert) - +import Test.Assert (assert, ASSERT) + +testArrayST :: forall t. + Eff + ( console :: CONSOLE + , assert :: ASSERT + | t + ) + Unit testArrayST = do log "emptySTArray should produce an empty array" diff --git a/test/Test/Data/Array/Unsafe.purs b/test/Test/Data/Array/Unsafe.purs index 49caad09..46e584c4 100644 --- a/test/Test/Data/Array/Unsafe.purs +++ b/test/Test/Data/Array/Unsafe.purs @@ -1,10 +1,18 @@ module Test.Data.Array.Unsafe (testArrayUnsafe) where -import Prelude -import Control.Monad.Eff.Console (log) -import Data.Array.Unsafe -import Test.Assert (assert) +import Prelude ((==), ($), bind, Unit) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Console (log, CONSOLE) +import Data.Array.Unsafe (init, last, tail, head) +import Test.Assert (assert, ASSERT) +testArrayUnsafe :: forall t. + Eff + ( console :: CONSOLE + , assert :: ASSERT + | t + ) + Unit testArrayUnsafe = do log "head should return the first item in an array" diff --git a/test/Test/Main.purs b/test/Test/Main.purs index 7a5275ec..e282931c 100644 --- a/test/Test/Main.purs +++ b/test/Test/Main.purs @@ -1,10 +1,20 @@ module Test.Main where -import Prelude -import Test.Data.Array -import Test.Data.Array.ST -import Test.Data.Array.Unsafe +import Prelude (bind, Unit) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Console (CONSOLE) +import Test.Assert (ASSERT) +import Test.Data.Array (testArray) +import Test.Data.Array.ST (testArrayST) +import Test.Data.Array.Unsafe (testArrayUnsafe) +main :: forall t. + Eff + ( console :: CONSOLE + , assert :: ASSERT + | t + ) + Unit main = do testArray testArrayST