Skip to content

Commit ad16507

Browse files
committed
Merge pull request #6 from purescript/0.8-updates
Updates for PureScript 0.8
2 parents eadcc23 + 4af2cc5 commit ad16507

File tree

8 files changed

+70
-137
lines changed

8 files changed

+70
-137
lines changed

.travis.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
language: node_js
2-
sudo: false
3-
node_js:
4-
- 0.10
2+
sudo: required
3+
dist: trusty
4+
node_js: 5
55
env:
66
- PATH=$HOME/purescript:$PATH
77
install:
88
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
99
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
1010
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
1111
- chmod a+x $HOME/purescript
12+
- npm install -g bower
1213
- npm install
14+
- bower install
1315
script:
14-
- npm run build
16+
- npm test
17+
after_success:
18+
- >-
19+
test $TRAVIS_TAG &&
20+
psc-publish > .pursuit.json &&
21+
curl -X POST http://pursuit.purescript.org/packages \
22+
-d @.pursuit.json \
23+
-H 'Accept: application/json' \
24+
-H "Authorization: token ${GITHUB_TOKEN}"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ Unfoldable functors.
1212
bower install purescript-unfoldable
1313
```
1414

15-
## Module documentation
15+
## Documentation
1616

17-
- [Data.Unfoldable](docs/Data/Unfoldable.md)
17+
Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-unfoldable).

bower.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
"name": "purescript-unfoldable",
33
"homepage": "https://github.com/purescript/purescript-unfoldable",
44
"description": "Unfoldable Functors",
5-
"keywords": [
6-
"purescript"
7-
],
85
"license": "MIT",
96
"repository": {
107
"type": "git",
@@ -20,11 +17,11 @@
2017
"package.json"
2118
],
2219
"dependencies": {
23-
"purescript-arrays": "^0.4.0",
24-
"purescript-tuples": "^0.4.0"
20+
"purescript-arrays": "^1.0.0-rc.1",
21+
"purescript-tuples": "^1.0.0-rc.1"
2522
},
2623
"devDependencies": {
27-
"purescript-console": "^0.1.0",
28-
"purescript-assert": "^0.1.0"
24+
"purescript-assert": "^1.0.0-rc.1",
25+
"purescript-console": "^1.0.0-rc.1"
2926
}
3027
}

docs/Data/Unfoldable.md

Lines changed: 0 additions & 77 deletions
This file was deleted.

examples/Collatz.purs

Lines changed: 0 additions & 21 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"private": true,
33
"scripts": {
4-
"postinstall": "pulp dep install",
5-
"build": "pulp build && pulp test && rimraf docs && pulp docs"
4+
"clean": "rimraf output && rimraf .pulp-cache",
5+
"build": "pulp build",
6+
"test": "pulp test"
67
},
78
"devDependencies": {
8-
"pulp": "^4.0.2",
9-
"rimraf": "^2.4.1"
9+
"pulp": "^8.1.0",
10+
"rimraf": "^2.5.0"
1011
}
1112
}

src/Data/Unfoldable.purs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66

77
module Data.Unfoldable where
88

9-
import Prelude (class Applicative, unit, const, (-), (<=), return, bind, ($))
9+
import Prelude
1010

11-
import Data.Maybe (Maybe(Nothing, Just))
12-
import Data.Tuple (Tuple(Tuple))
13-
import Data.Array.ST (pushSTArray, emptySTArray, runSTArray)
14-
import Data.Traversable (class Traversable, sequence)
1511
import Control.Monad.Eff (untilE, runPure)
1612
import Control.Monad.ST (writeSTRef, readSTRef, newSTRef)
1713

14+
import Data.Array.ST (pushSTArray, emptySTArray, runSTArray)
15+
import Data.Maybe (Maybe(..))
16+
import Data.Traversable (class Traversable, sequence)
17+
import Data.Tuple (Tuple(..))
18+
1819
-- | This class identifies data structures which can be _unfolded_,
1920
-- | generalizing `unfoldr` on arrays.
2021
-- |
@@ -33,20 +34,20 @@ instance unfoldableArray :: Unfoldable Array where
3334
untilE $ do
3435
b1 <- readSTRef seed
3536
case f b1 of
36-
Nothing -> return true
37+
Nothing -> pure true
3738
Just (Tuple a b2) -> do
3839
pushSTArray arr a
3940
writeSTRef seed b2
40-
return false
41-
return arr))
41+
pure false
42+
pure arr))
4243

4344
-- | Replicate a value some natural number of times.
4445
-- | For example:
4546
-- |
4647
-- | ~~~ purescript
4748
-- | replicate 2 "foo" == ["foo", "foo"] :: Array String
4849
-- | ~~~
49-
replicate :: forall f a. (Unfoldable f) => Int -> a -> f a
50+
replicate :: forall f a. Unfoldable f => Int -> a -> f a
5051
replicate n v = unfoldr step n
5152
where
5253
step :: Int -> Maybe (Tuple a Int)
@@ -55,8 +56,12 @@ replicate n v = unfoldr step n
5556
else Just (Tuple v (i - 1))
5657

5758
-- | Perform an Applicative action `n` times, and accumulate all the results.
58-
replicateA :: forall m f a. (Applicative m, Unfoldable f, Traversable f) =>
59-
Int -> m a -> m (f a)
59+
replicateA
60+
:: forall m f a
61+
. (Applicative m, Unfoldable f, Traversable f)
62+
=> Int
63+
-> m a
64+
-> m (f a)
6065
replicateA n m = sequence (replicate n m)
6166

6267
-- | The container with no elements - unfolded with zero iterations.
@@ -65,7 +70,7 @@ replicateA n m = sequence (replicate n m)
6570
-- | ~~~ purescript
6671
-- | none == [] :: forall a. Array a
6772
-- | ~~~
68-
none :: forall f a. (Unfoldable f) => f a
73+
none :: forall f a. Unfoldable f => f a
6974
none = unfoldr (const Nothing) unit
7075

7176
-- | Contain a single value.
@@ -74,5 +79,5 @@ none = unfoldr (const Nothing) unit
7479
-- | ~~~ purescript
7580
-- | singleton "foo" == ["foo"] :: Array String
7681
-- | ~~~
77-
singleton :: forall f a. (Unfoldable f) => a -> f a
82+
singleton :: forall f a. Unfoldable f => a -> f a
7883
singleton = replicate 1

test/Main.purs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,42 @@ module Test.Main where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff())
6-
import Control.Monad.Eff.Console
7-
import Data.Maybe
8-
import Data.Unfoldable
9-
import Test.Assert
5+
import Control.Monad.Eff (Eff)
6+
import Control.Monad.Eff.Console (CONSOLE, log, logShow)
107

8+
import Data.Maybe (Maybe(..))
9+
import Data.Tuple (Tuple(..))
10+
import Data.Unfoldable as U
11+
12+
import Test.Assert (ASSERT, assert)
13+
14+
collatz :: Int -> Array Int
15+
collatz = U.unfoldr step
16+
where
17+
step 1 = Nothing
18+
step n =
19+
Just $
20+
Tuple n $
21+
if n `mod` 2 == 0
22+
then n / 2
23+
else n * 3 + 1
24+
25+
main :: Eff (assert :: ASSERT, console :: CONSOLE) Unit
1126
main = do
27+
log "Collatz 1000"
28+
logShow $ collatz 1000
29+
1230
log "Test none"
13-
assert $ none == [] :: Array Unit
31+
assert $ U.none == [] :: Array Unit
1432

1533
log "Test singleton"
16-
assert $ singleton unit == [unit]
34+
assert $ U.singleton unit == [unit]
1735

1836
log "Test replicate"
19-
assert $ replicate 3 "foo" == ["foo", "foo", "foo"]
37+
assert $ U.replicate 3 "foo" == ["foo", "foo", "foo"]
2038

2139
log "Test replicateA"
22-
assert $ replicateA 3 [1,2] == [
40+
assert $ U.replicateA 3 [1,2] == [
2341
[1,1,1],[1,1,2], [1,2,1],[1,2,2],
2442
[2,1,1],[2,1,2], [2,2,1],[2,2,2]
2543
]

0 commit comments

Comments
 (0)