Skip to content

Commit a15b85a

Browse files
committed
Merge pull request #3 from purescript/0.8-updates
Update for PureScript 0.8
2 parents c117e4d + 357753d commit a15b85a

File tree

6 files changed

+47
-140
lines changed

6 files changed

+47
-140
lines changed

.travis.yml

Lines changed: 13 additions & 3 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:
1416
- npm run build
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 @@ A data structure and functions for graphs.
1212
bower install purescript-graphs
1313
```
1414

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

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

bower.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
"authors": [
55
"Phil Freeman <[email protected]>"
66
],
7-
"keywords": [
8-
"purescript"
9-
],
107
"repository": {
118
"type": "git",
129
"url": "git://github.com/purescript/purescript-graphs.git"
@@ -17,13 +14,11 @@
1714
"bower_components",
1815
"node_modules",
1916
"output",
20-
"tests",
21-
"tmp",
17+
"test",
2218
"bower.json",
23-
"Gruntfile.js",
2419
"package.json"
2520
],
2621
"dependencies": {
27-
"purescript-sets": "^0.5.0"
22+
"purescript-sets": "^1.0.0-rc.1"
2823
}
2924
}

docs/Data/Graph.md

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

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"private": true,
33
"scripts": {
4-
"postinstall": "pulp dep install",
5-
"build": "pulp build && rimraf docs && pulp docs"
4+
"clean": "rimraf output && rimraf .pulp-cache",
5+
"build": "pulp build"
66
},
77
"devDependencies": {
8-
"pulp": "^4.0.2",
9-
"rimraf": "^2.4.1"
8+
"pulp": "^8.1.0",
9+
"rimraf": "^2.5.0"
1010
}
1111
}

src/Data/Graph.purs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
11
-- | A data structure and functions for graphs
22

3-
module Data.Graph (
4-
Edge(..),
5-
Graph(..),
6-
SCC(..),
7-
8-
vertices,
9-
10-
scc,
11-
scc',
12-
13-
topSort,
14-
topSort'
3+
module Data.Graph
4+
( Edge(..)
5+
, Graph(..)
6+
, SCC(..)
7+
, vertices
8+
, scc
9+
, scc'
10+
, topSort
11+
, topSort'
1512
) where
1613

17-
import Prelude (class Ord, class Eq, class Show, (<<<), id, ($), (<), (==), (&&), not, unit, return, bind, (++), flip, map, one, (+), zero, show)
14+
import Prelude
1815

19-
import Data.Maybe (Maybe(Just, Nothing), isNothing)
20-
import Data.List (List(Cons, Nil), concatMap, reverse, singleton)
21-
import Data.Foldable (any, for_, elem)
22-
import Data.Traversable (for)
23-
24-
import Control.Monad (when)
2516
import Control.Monad.Eff (runPure)
2617
import Control.Monad.ST (writeSTRef, modifySTRef, readSTRef, newSTRef, runST)
2718

19+
import Data.Foldable (any, for_, elem)
20+
import Data.List (List(..), concatMap, reverse, singleton)
2821
import Data.Map as M
22+
import Data.Maybe (Maybe(..), isNothing)
23+
import Data.Traversable (for)
2924

3025
-- | An directed edge between vertices labelled with keys of type `k`.
3126
data Edge k = Edge k k
@@ -35,8 +30,6 @@ data Edge k = Edge k k
3530
-- | Edges refer to vertices using keys of type `k`.
3631
data Graph k v = Graph (List v) (List (Edge k))
3732

38-
type Index = Int
39-
4033
-- | A strongly-connected component of a graph.
4134
-- |
4235
-- | - `AcyclicSCC` identifies strongly-connected components consisting of a single vertex.
@@ -45,8 +38,8 @@ type Index = Int
4538
data SCC v = AcyclicSCC v | CyclicSCC (List v)
4639

4740
instance showSCC :: (Show v) => Show (SCC v) where
48-
show (AcyclicSCC v) = "AcyclicSCC (" ++ show v ++ ")"
49-
show (CyclicSCC vs) = "CyclicSCC " ++ show vs
41+
show (AcyclicSCC v) = "(AcyclicSCC " <> show v <> ")"
42+
show (CyclicSCC vs) = "(CyclicSCC " <> show vs <> ")"
5043

5144
instance eqSCC :: (Eq v) => Eq (SCC v) where
5245
eq (AcyclicSCC v1) (AcyclicSCC v2) = v1 == v2
@@ -59,14 +52,14 @@ vertices (AcyclicSCC v) = singleton v
5952
vertices (CyclicSCC vs) = vs
6053

6154
-- | Compute the strongly connected components of a graph.
62-
scc :: forall v. (Eq v, Ord v) => Graph v v -> List (SCC v)
55+
scc :: forall v. Ord v => Graph v v -> List (SCC v)
6356
scc = scc' id id
6457

6558
-- | Compute the strongly connected components of a graph.
6659
-- |
6760
-- | This function is a slight generalization of `scc` which allows key and value types
6861
-- | to differ.
69-
scc' :: forall k v. (Eq k, Ord k) => (v -> k) -> (k -> v) -> Graph k v -> List (SCC v)
62+
scc' :: forall k v. Ord k => (v -> k) -> (k -> v) -> Graph k v -> List (SCC v)
7063
scc' makeKey makeVert (Graph vs es) = runPure (runST (do
7164
index <- newSTRef zero
7265
path <- newSTRef Nil
@@ -79,13 +72,13 @@ scc' makeKey makeVert (Graph vs es) = runPure (runST (do
7972

8073
indexOfKey k = do
8174
m <- readSTRef indexMap
82-
return $ M.lookup k m
75+
pure $ M.lookup k m
8376

8477
lowlinkOf v = lowlinkOfKey (makeKey v)
8578

8679
lowlinkOfKey k = do
8780
m <- readSTRef lowlinkMap
88-
return $ M.lookup k m
81+
pure $ M.lookup k m
8982

9083
go Nil = readSTRef components
9184
go (Cons v vs) = do
@@ -126,34 +119,34 @@ scc' makeKey makeVert (Graph vs es) = runPure (runST (do
126119
when (vIndex == vLowlink) $ do
127120
currentPath <- readSTRef path
128121
let newPath = popUntil makeKey v currentPath Nil
129-
modifySTRef components $ flip (++) (singleton (makeComponent newPath.component))
122+
modifySTRef components $ flip (<>) (singleton (makeComponent newPath.component))
130123
writeSTRef path newPath.path
131-
return unit
124+
pure unit
132125

133126
makeComponent (Cons v Nil) | not (isCycle (makeKey v)) = AcyclicSCC v
134127
makeComponent vs = CyclicSCC vs
135128

136129
isCycle k = any (\(Edge k1 k2) -> k1 == k && k2 == k) es
137130
in go vs)))
138131

139-
popUntil :: forall k v. (Eq k) => (v -> k) -> v -> List v -> List v -> { path :: List v, component :: List v }
132+
popUntil :: forall k v. Eq k => (v -> k) -> v -> List v -> List v -> { path :: List v, component :: List v }
140133
popUntil _ _ Nil popped = { path: Nil, component: popped }
141134
popUntil makeKey v (Cons w path) popped | makeKey v == makeKey w = { path: path, component: Cons w popped }
142135
popUntil makeKey v (Cons w ws) popped = popUntil makeKey v ws (Cons w popped)
143136

144-
maybeMin :: Index -> Maybe Index -> Maybe Index
137+
maybeMin :: Int -> Maybe Int -> Maybe Int
145138
maybeMin i Nothing = Just i
146139
maybeMin i (Just j) = Just $ min i j
147140
where
148141
min x y = if x < y then x else y
149142

150143
-- | Topologically sort the vertices of a graph
151-
topSort :: forall v. (Eq v, Ord v) => Graph v v -> List v
144+
topSort :: forall v. Ord v => Graph v v -> List v
152145
topSort = topSort' id id
153146

154147
-- | Topologically sort the vertices of a graph
155148
-- |
156149
-- | This function is a slight generalization of `scc` which allows key and value types
157150
-- | to differ.
158-
topSort' :: forall k v. (Eq k, Ord k) => (v -> k) -> (k -> v) -> Graph k v -> List v
151+
topSort' :: forall k v. Ord k => (v -> k) -> (k -> v) -> Graph k v -> List v
159152
topSort' makeKey makeVert = reverse <<< concatMap vertices <<< scc' makeKey makeVert

0 commit comments

Comments
 (0)