Skip to content

Commit 88e724d

Browse files
paluhkl0tlsrghmaJordanMartinez
authored
Update to v0.14.0-rc3 (#181)
* Update TAG to v0.14.0-rc3; dependencies to master; psa to v0.8.0 * Add roles declarations to allow safe coercions * fix: Fix `Foldable1 NonEmptyArray` instance (requires purescript/purescript-nonempty#39) * fix: Fix `Foldable1 NonEmptyArray` instance -> swap foldl1Impl and foldr1Impl * Fix warning by removing 'kind' word in import Co-authored-by: Cyril Sobierajewicz <[email protected]> Co-authored-by: Serhii Khoma <[email protected]> Co-authored-by: JordanMartinez <[email protected]>
1 parent 72e4b24 commit 88e724d

File tree

7 files changed

+51
-25
lines changed

7 files changed

+51
-25
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ node_js: stable
55
env:
66
- PATH=$HOME/purescript:$PATH
77
install:
8-
- TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest))
8+
# - TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest))
9+
- TAG=v0.14.0-rc3
910
- curl --location --output $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
1011
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
1112
- chmod a+x $HOME/purescript

bower.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@
1515
"package.json"
1616
],
1717
"dependencies": {
18-
"purescript-bifunctors": "^4.0.0",
19-
"purescript-control": "^4.0.0",
20-
"purescript-foldable-traversable": "^4.0.0",
21-
"purescript-maybe": "^4.0.0",
22-
"purescript-nonempty": "^5.0.0",
23-
"purescript-partial": "^2.0.0",
24-
"purescript-prelude": "^4.0.0",
25-
"purescript-st": "^4.0.0",
26-
"purescript-tailrec": "^4.0.0",
27-
"purescript-tuples": "^5.0.0",
28-
"purescript-unfoldable": "^4.0.0",
29-
"purescript-unsafe-coerce": "^4.0.0"
18+
"purescript-bifunctors": "master",
19+
"purescript-control": "master",
20+
"purescript-foldable-traversable": "master",
21+
"purescript-maybe": "master",
22+
"purescript-nonempty": "master",
23+
"purescript-partial": "master",
24+
"purescript-prelude": "master",
25+
"purescript-st": "master",
26+
"purescript-tailrec": "master",
27+
"purescript-tuples": "master",
28+
"purescript-unfoldable": "master",
29+
"purescript-unsafe-coerce": "master"
3030
},
3131
"devDependencies": {
32-
"purescript-assert": "^4.0.0",
33-
"purescript-console": "^4.0.0",
34-
"purescript-const": "^4.0.0"
32+
"purescript-assert": "master",
33+
"purescript-console": "master",
34+
"purescript-const": "master"
3535
}
3636
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"devDependencies": {
99
"eslint": "^4.19.1",
1010
"pulp": "^15.0.0",
11-
"purescript-psa": "^0.6.0",
11+
"purescript-psa": "^0.8.0",
1212
"rimraf": "^2.6.2"
1313
}
1414
}

src/Data/Array/NonEmpty/Internal.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
"use strict";
22

3-
exports.fold1Impl = function (f) {
3+
exports.foldr1Impl = function (f) {
4+
return function (xs) {
5+
var acc = xs[xs.length - 1];
6+
for (var i = xs.length - 2; i >= 0; i--) {
7+
acc = f(xs[i])(acc);
8+
}
9+
return acc;
10+
};
11+
};
12+
13+
exports.foldl1Impl = function (f) {
414
return function (xs) {
515
var acc = xs[0];
616
var len = xs.length;

src/Data/Array/NonEmpty/Internal.purs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ derive newtype instance foldableWithIndexNonEmptyArray :: FoldableWithIndex Int
3535

3636
instance foldable1NonEmptyArray :: Foldable1 NonEmptyArray where
3737
foldMap1 = foldMap1Default
38-
fold1 = fold1Impl (<>)
38+
fold1 = foldl1Impl (<>)
39+
foldr1 = foldr1Impl
40+
foldl1 = foldl1Impl
3941

4042
derive newtype instance unfoldable1NonEmptyArray :: Unfoldable1 NonEmptyArray
4143
derive newtype instance traversableNonEmptyArray :: Traversable NonEmptyArray
@@ -56,7 +58,8 @@ derive newtype instance monadNonEmptyArray :: Monad NonEmptyArray
5658
derive newtype instance altNonEmptyArray :: Alt NonEmptyArray
5759

5860
-- we use FFI here to avoid the unncessary copy created by `tail`
59-
foreign import fold1Impl :: forall a. (a -> a -> a) -> NonEmptyArray a -> a
61+
foreign import foldr1Impl :: forall a. (a -> a -> a) -> NonEmptyArray a -> a
62+
foreign import foldl1Impl :: forall a. (a -> a -> a) -> NonEmptyArray a -> a
6063

6164
foreign import traverse1Impl
6265
:: forall m a b

src/Data/Array/ST.purs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module Data.Array.ST
3131
import Prelude
3232

3333
import Control.Monad.ST as ST
34-
import Control.Monad.ST (ST, kind Region)
34+
import Control.Monad.ST (ST, Region)
3535
import Data.Maybe (Maybe(..))
3636

3737
-- | A reference to a mutable array.
@@ -43,6 +43,8 @@ import Data.Maybe (Maybe(..))
4343
-- | except that mutation is allowed.
4444
foreign import data STArray :: Region -> Type -> Type
4545

46+
type role STArray nominal representational
47+
4648
-- | An element and its index.
4749
type Assoc a = { value :: a, index :: Int }
4850

test/Test/Data/Array/NonEmpty.purs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Data.FunctorWithIndex (mapWithIndex)
1010
import Data.Maybe (Maybe(..), fromJust)
1111
import Data.Monoid.Additive (Additive(..))
1212
import Data.NonEmpty ((:|))
13-
import Data.Semigroup.Foldable (foldMap1)
13+
import Data.Semigroup.Foldable (foldMap1, foldr1, foldl1)
1414
import Data.Semigroup.Traversable (traverse1)
1515
import Data.Tuple (Tuple(..))
1616
import Data.Unfoldable1 as U1
@@ -305,12 +305,22 @@ testNonEmptyArray = do
305305
log "Unfoldable instance"
306306
assert $ U1.range 0 9 == NEA.range 0 9
307307

308-
log "foldl should work"
308+
log "foldMap1 should work"
309+
assert $ foldMap1 Additive (fromArray [1, 2, 3, 4]) == Additive 10
310+
311+
log "fold1 should work"
309312
-- test through sum
310313
assert $ sum (fromArray [1, 2, 3, 4]) == 10
311314

312-
log "foldMap1 should work"
313-
assert $ foldMap1 Additive (fromArray [1, 2, 3, 4]) == Additive 10
315+
log "foldr1 should work"
316+
assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b", "c", "d"]) == "(a(b(cd)))"
317+
assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b"]) == "(ab)"
318+
assert $ foldr1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a"]) == "a"
319+
320+
log "foldl1 should work"
321+
assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b", "c", "d"]) == "(((ab)c)d)"
322+
assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a", "b"]) == "(ab)"
323+
assert $ foldl1 (\l r -> "(" <> l <> r <> ")") (fromArray ["a"]) == "a"
314324

315325
log "traverse1 should work"
316326
assert $ traverse1 Just (fromArray [1, 2, 3, 4]) == NEA.fromArray [1, 2, 3, 4]

0 commit comments

Comments
 (0)