From ca78b30de0c9a897f58ffe6c9fde0278aa07030e Mon Sep 17 00:00:00 2001 From: Tomasz Rybarczyk Date: Tue, 20 Oct 2020 23:00:09 +0200 Subject: [PATCH 1/5] Update TAG to v0.14.0-rc3; dependencies to master; psa to v0.8.0 --- .travis.yml | 3 ++- bower.json | 30 +++++++++++++++--------------- package.json | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8daa38c1..116705f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,8 @@ node_js: stable env: - PATH=$HOME/purescript:$PATH install: - - TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest)) + # - TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest)) + - TAG=v0.14.0-rc3 - curl --location --output $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz - tar -xvf $HOME/purescript.tar.gz -C $HOME/ - chmod a+x $HOME/purescript diff --git a/bower.json b/bower.json index 4e217646..3b108a88 100644 --- a/bower.json +++ b/bower.json @@ -15,22 +15,22 @@ "package.json" ], "dependencies": { - "purescript-bifunctors": "^4.0.0", - "purescript-control": "^4.0.0", - "purescript-foldable-traversable": "^4.0.0", - "purescript-maybe": "^4.0.0", - "purescript-nonempty": "^5.0.0", - "purescript-partial": "^2.0.0", - "purescript-prelude": "^4.0.0", - "purescript-st": "^4.0.0", - "purescript-tailrec": "^4.0.0", - "purescript-tuples": "^5.0.0", - "purescript-unfoldable": "^4.0.0", - "purescript-unsafe-coerce": "^4.0.0" + "purescript-bifunctors": "master", + "purescript-control": "master", + "purescript-foldable-traversable": "master", + "purescript-maybe": "master", + "purescript-nonempty": "master", + "purescript-partial": "master", + "purescript-prelude": "master", + "purescript-st": "master", + "purescript-tailrec": "master", + "purescript-tuples": "master", + "purescript-unfoldable": "master", + "purescript-unsafe-coerce": "master" }, "devDependencies": { - "purescript-assert": "^4.0.0", - "purescript-console": "^4.0.0", - "purescript-const": "^4.0.0" + "purescript-assert": "master", + "purescript-console": "master", + "purescript-const": "master" } } diff --git a/package.json b/package.json index 42af30f1..8985bcfd 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "devDependencies": { "eslint": "^4.19.1", "pulp": "^15.0.0", - "purescript-psa": "^0.6.0", + "purescript-psa": "^0.8.0", "rimraf": "^2.6.2" } } From 8ab23b7473bb06f6eb2eed3e10f211e4bc0b927a Mon Sep 17 00:00:00 2001 From: Cyril Sobierajewicz Date: Sat, 18 Jul 2020 19:21:59 +0200 Subject: [PATCH 2/5] Add roles declarations to allow safe coercions --- src/Data/Array/ST.purs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Data/Array/ST.purs b/src/Data/Array/ST.purs index 4a57939d..2b3e030b 100644 --- a/src/Data/Array/ST.purs +++ b/src/Data/Array/ST.purs @@ -43,6 +43,8 @@ import Data.Maybe (Maybe(..)) -- | except that mutation is allowed. foreign import data STArray :: Region -> Type -> Type +type role STArray nominal representational + -- | An element and its index. type Assoc a = { value :: a, index :: Int } From 38b691e16e9957d51f49c0e24753621ae9c8b430 Mon Sep 17 00:00:00 2001 From: Serhii Khoma Date: Sat, 24 Oct 2020 14:01:06 +0300 Subject: [PATCH 3/5] fix: Fix `Foldable1 NonEmptyArray` instance (requires https://github.com/purescript/purescript-nonempty/pull/39) --- src/Data/Array/NonEmpty/Internal.js | 12 +++++++++++- src/Data/Array/NonEmpty/Internal.purs | 7 +++++-- test/Test/Data/Array/NonEmpty.purs | 18 ++++++++++++++---- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/Data/Array/NonEmpty/Internal.js b/src/Data/Array/NonEmpty/Internal.js index 0971fc45..3beb3055 100644 --- a/src/Data/Array/NonEmpty/Internal.js +++ b/src/Data/Array/NonEmpty/Internal.js @@ -1,6 +1,6 @@ "use strict"; -exports.fold1Impl = function (f) { +exports.foldr1Impl = function (f) { return function (xs) { var acc = xs[0]; var len = xs.length; @@ -11,6 +11,16 @@ exports.fold1Impl = function (f) { }; }; +exports.foldl1Impl = function (f) { + return function (xs) { + var acc = xs[xs.length - 1]; + for (var i = xs.length - 2; i >= 0; i--) { + acc = f(xs[i])(acc); + } + return acc; + }; +}; + exports.traverse1Impl = function () { function Cont(fn) { this.fn = fn; diff --git a/src/Data/Array/NonEmpty/Internal.purs b/src/Data/Array/NonEmpty/Internal.purs index 1603bd05..819ace8f 100644 --- a/src/Data/Array/NonEmpty/Internal.purs +++ b/src/Data/Array/NonEmpty/Internal.purs @@ -35,7 +35,9 @@ derive newtype instance foldableWithIndexNonEmptyArray :: FoldableWithIndex Int instance foldable1NonEmptyArray :: Foldable1 NonEmptyArray where foldMap1 = foldMap1Default - fold1 = fold1Impl (<>) + fold1 = foldr1Impl (<>) + foldr1 = foldr1Impl + foldl1 = foldl1Impl derive newtype instance unfoldable1NonEmptyArray :: Unfoldable1 NonEmptyArray derive newtype instance traversableNonEmptyArray :: Traversable NonEmptyArray @@ -56,7 +58,8 @@ derive newtype instance monadNonEmptyArray :: Monad NonEmptyArray derive newtype instance altNonEmptyArray :: Alt NonEmptyArray -- we use FFI here to avoid the unncessary copy created by `tail` -foreign import fold1Impl :: forall a. (a -> a -> a) -> NonEmptyArray a -> a +foreign import foldr1Impl :: forall a. (a -> a -> a) -> NonEmptyArray a -> a +foreign import foldl1Impl :: forall a. (a -> a -> a) -> NonEmptyArray a -> a foreign import traverse1Impl :: forall m a b diff --git a/test/Test/Data/Array/NonEmpty.purs b/test/Test/Data/Array/NonEmpty.purs index ba791e2b..d9823451 100644 --- a/test/Test/Data/Array/NonEmpty.purs +++ b/test/Test/Data/Array/NonEmpty.purs @@ -10,7 +10,7 @@ import Data.FunctorWithIndex (mapWithIndex) import Data.Maybe (Maybe(..), fromJust) import Data.Monoid.Additive (Additive(..)) import Data.NonEmpty ((:|)) -import Data.Semigroup.Foldable (foldMap1) +import Data.Semigroup.Foldable (foldMap1, foldr1, foldl1) import Data.Semigroup.Traversable (traverse1) import Data.Tuple (Tuple(..)) import Data.Unfoldable1 as U1 @@ -305,12 +305,22 @@ testNonEmptyArray = do log "Unfoldable instance" assert $ U1.range 0 9 == NEA.range 0 9 - log "foldl should work" + log "foldMap1 should work" + assert $ foldMap1 Additive (fromArray [1, 2, 3, 4]) == Additive 10 + + log "fold1 should work" -- test through sum assert $ sum (fromArray [1, 2, 3, 4]) == 10 - log "foldMap1 should work" - assert $ foldMap1 Additive (fromArray [1, 2, 3, 4]) == Additive 10 + log "foldr1 should work" + assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b", "c", "d"]) == "(((ab)c)d)" + assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b"]) == "(ab)" + assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a"]) == "a" + + log "foldl1 should work" + assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b", "c", "d"]) == "(a(b(cd)))" + assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b"]) == "(ab)" + assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a"]) == "a" log "traverse1 should work" assert $ traverse1 Just (fromArray [1, 2, 3, 4]) == NEA.fromArray [1, 2, 3, 4] From 686ae1b1bae4840ed5484d14a3ba4d9b306627a5 Mon Sep 17 00:00:00 2001 From: Serhii Khoma Date: Sat, 24 Oct 2020 19:10:44 +0300 Subject: [PATCH 4/5] fix: Fix `Foldable1 NonEmptyArray` instance -> swap foldl1Impl and foldr1Impl --- src/Data/Array/NonEmpty/Internal.js | 14 +++++++------- src/Data/Array/NonEmpty/Internal.purs | 2 +- test/Test/Data/Array/NonEmpty.purs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Data/Array/NonEmpty/Internal.js b/src/Data/Array/NonEmpty/Internal.js index 3beb3055..40d88a75 100644 --- a/src/Data/Array/NonEmpty/Internal.js +++ b/src/Data/Array/NonEmpty/Internal.js @@ -2,10 +2,9 @@ exports.foldr1Impl = function (f) { return function (xs) { - var acc = xs[0]; - var len = xs.length; - for (var i = 1; i < len; i++) { - acc = f(acc)(xs[i]); + var acc = xs[xs.length - 1]; + for (var i = xs.length - 2; i >= 0; i--) { + acc = f(xs[i])(acc); } return acc; }; @@ -13,9 +12,10 @@ exports.foldr1Impl = function (f) { exports.foldl1Impl = function (f) { return function (xs) { - var acc = xs[xs.length - 1]; - for (var i = xs.length - 2; i >= 0; i--) { - acc = f(xs[i])(acc); + var acc = xs[0]; + var len = xs.length; + for (var i = 1; i < len; i++) { + acc = f(acc)(xs[i]); } return acc; }; diff --git a/src/Data/Array/NonEmpty/Internal.purs b/src/Data/Array/NonEmpty/Internal.purs index 819ace8f..3d87a69e 100644 --- a/src/Data/Array/NonEmpty/Internal.purs +++ b/src/Data/Array/NonEmpty/Internal.purs @@ -35,7 +35,7 @@ derive newtype instance foldableWithIndexNonEmptyArray :: FoldableWithIndex Int instance foldable1NonEmptyArray :: Foldable1 NonEmptyArray where foldMap1 = foldMap1Default - fold1 = foldr1Impl (<>) + fold1 = foldl1Impl (<>) foldr1 = foldr1Impl foldl1 = foldl1Impl diff --git a/test/Test/Data/Array/NonEmpty.purs b/test/Test/Data/Array/NonEmpty.purs index d9823451..b42c08e9 100644 --- a/test/Test/Data/Array/NonEmpty.purs +++ b/test/Test/Data/Array/NonEmpty.purs @@ -313,12 +313,12 @@ testNonEmptyArray = do assert $ sum (fromArray [1, 2, 3, 4]) == 10 log "foldr1 should work" - assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b", "c", "d"]) == "(((ab)c)d)" + assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b", "c", "d"]) == "(a(b(cd)))" assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b"]) == "(ab)" assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a"]) == "a" log "foldl1 should work" - assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b", "c", "d"]) == "(a(b(cd)))" + assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b", "c", "d"]) == "(((ab)c)d)" assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b"]) == "(ab)" assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a"]) == "a" From dd7cc595301b8ef5fd3e22b9a487d0f0717ac885 Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Fri, 6 Nov 2020 06:40:58 -0800 Subject: [PATCH 5/5] Fix warning by removing 'kind' word in import --- src/Data/Array/ST.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/Array/ST.purs b/src/Data/Array/ST.purs index 2b3e030b..32f7c274 100644 --- a/src/Data/Array/ST.purs +++ b/src/Data/Array/ST.purs @@ -31,7 +31,7 @@ module Data.Array.ST import Prelude import Control.Monad.ST as ST -import Control.Monad.ST (ST, kind Region) +import Control.Monad.ST (ST, Region) import Data.Maybe (Maybe(..)) -- | A reference to a mutable array.