Skip to content

Update for PureScript 0.11 #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"parserOptions": {
"ecmaVersion": 5
},
"extends": "eslint:recommended",
"env": {
"commonjs": true
},
"rules": {
"strict": [2, "global"],
"block-scoped-var": 2,
"consistent-return": 2,
"eqeqeq": [2, "smart"],
"guard-for-in": 2,
"no-caller": 2,
"no-extend-native": 2,
"no-loop-func": 2,
"no-new": 2,
"no-param-reassign": 2,
"no-return-assign": 2,
"no-unused-expressions": 2,
"no-use-before-define": 2,
"radix": [2, "always"],
"indent": [2, 2],
"quotes": [2, "double"],
"semi": [2, "always"]
}
}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/.*
!/.gitignore
!/.jscsrc
!/.jshintrc
!/.eslintrc.json
!/.travis.yml
/bower_components/
/node_modules/
Expand Down
17 changes: 0 additions & 17 deletions .jscsrc

This file was deleted.

20 changes: 0 additions & 20 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
dist: trusty
sudo: required
node_js: 6
node_js: stable
env:
- PATH=$HOME/purescript:$PATH
install:
Expand Down
22 changes: 11 additions & 11 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
"package.json"
],
"dependencies": {
"purescript-foldable-traversable": "^2.0.0",
"purescript-nonempty": "^3.0.0",
"purescript-partial": "^1.1.0",
"purescript-st": "^2.0.0",
"purescript-tailrec": "^2.0.0",
"purescript-tuples": "^3.0.0",
"purescript-unfoldable": "^2.0.0",
"purescript-unsafe-coerce": "^2.0.0"
"purescript-foldable-traversable": "^3.0.0",
"purescript-nonempty": "^4.0.0",
"purescript-partial": "^1.2.0",
"purescript-st": "^3.0.0",
"purescript-tailrec": "^3.0.0",
"purescript-tuples": "^4.0.0",
"purescript-unfoldable": "^3.0.0",
"purescript-unsafe-coerce": "^3.0.0"
},
"devDependencies": {
"purescript-assert": "^2.0.0",
"purescript-console": "^2.0.0",
"purescript-const": "^2.0.0"
"purescript-assert": "^3.0.0",
"purescript-console": "^3.0.0",
"purescript-const": "^3.0.0"
}
}
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
"private": true,
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "jshint src && jscs src && pulp build --censor-lib --strict",
"build": "eslint src && pulp build -- --censor-lib --strict",
"test": "pulp test"
},
"devDependencies": {
"jscs": "^2.8.0",
"jshint": "^2.9.1",
"pulp": "^9.0.1",
"purescript-psa": "^0.3.9",
"rimraf": "^2.5.0"
"eslint": "^3.17.1",
"pulp": "^10.0.4",
"purescript-psa": "^0.5.0-rc.1",
"rimraf": "^2.6.1"
}
}
11 changes: 7 additions & 4 deletions src/Data/Array.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ exports.range = function (start) {
return function (end) {
var step = start > end ? -1 : 1;
var result = [];
for (var i = start, n = 0; i !== end; i += step) {
var i = start, n = 0;
while (i !== end) {
result[n++] = i;
i += step;
}
result[n] = i;
return result;
Expand Down Expand Up @@ -44,9 +46,10 @@ exports.fromFoldableImpl = (function () {
function listToArray(list) {
var result = [];
var count = 0;
while (list !== emptyList) {
result[count++] = list.head;
list = list.tail;
var xs = list;
while (xs !== emptyList) {
result[count++] = xs.head;
xs = xs.tail;
}
return result;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Data/Array.purs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ import Prelude
import Control.Alt ((<|>))
import Control.Alternative (class Alternative)
import Control.Lazy (class Lazy, defer)
import Control.Monad.Rec.Class (class MonadRec, Step(..), tailRecM2)
import Control.Monad.Rec.Class (class MonadRec, Step(..), tailRecM2, tailRec)
import Control.Monad.ST (pureST)
import Data.Array.ST (unsafeFreeze, emptySTArray, pushSTArray)
import Data.Array.ST.Iterator (iterator, iterate, pushWhile)
Expand Down Expand Up @@ -164,15 +164,15 @@ infix 8 range as ..
-- |
-- | The `Lazy` constraint is used to generate the result lazily, to ensure
-- | termination.
some :: forall f a. (Alternative f, Lazy (f (Array a))) => f a -> f (Array a)
some :: forall f a. Alternative f => Lazy (f (Array a)) => f a -> f (Array a)
some v = (:) <$> v <*> defer (\_ -> many v)

-- | Attempt a computation multiple times, returning as many successful results
-- | as possible (possibly zero).
-- |
-- | The `Lazy` constraint is used to generate the result lazily, to ensure
-- | termination.
many :: forall f a. (Alternative f, Lazy (f (Array a))) => f a -> f (Array a)
many :: forall f a. Alternative f => Lazy (f (Array a)) => f a -> f (Array a)
many v = some v <|> pure []

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -521,13 +521,13 @@ span p arr =
{ init: arr, rest: [] }
where
breakIndex = go 0
go i =
go = tailRec \i ->
-- This looks like a good opportunity to use the Monad Maybe instance,
-- but it's important to write out an explicit case expression here in
-- order to ensure that TCO is triggered.
case index arr i of
Just x -> if p x then go (i+1) else Just i
Nothing -> Nothing
Just x -> if p x then Loop (i + 1) else Done (Just i)
Nothing -> Done Nothing

-- | Group equal, consecutive elements of an array into arrays.
-- |
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Array/ST.purs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Unsafe.Coerce (unsafeCoerce)
-- |
-- | The runtime representation of a value of type `STArray h a` is the same as that of `Array a`,
-- | except that mutation is allowed.
foreign import data STArray :: * -> * -> *
foreign import data STArray :: Type -> Type -> Type

-- | An element and its index.
type Assoc a = { value :: a, index :: Int }
Expand Down
20 changes: 10 additions & 10 deletions test/Test/Data/Array/ST.purs
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ testArrayST = do

assert $ run (do
arr <- emptySTArray
pushSTArray arr 1
pushSTArray arr 2
void $ pushSTArray arr 1
void $ pushSTArray arr 2
pure arr) == [1, 2]

assert $ run (do
arr <- thaw [1, 2, 3]
pushSTArray arr 4
void $ pushSTArray arr 4
pure arr) == [1, 2, 3, 4]

log "pushAllSTArray should append multiple values to the end of the array"

assert $ run (do
arr <- emptySTArray
pushAllSTArray arr [1, 2]
void $ pushAllSTArray arr [1, 2]
pure arr) == [1, 2]

assert $ run (do
arr <- thaw [1, 2, 3]
pushAllSTArray arr [4, 5, 6]
void $ pushAllSTArray arr [4, 5, 6]
pure arr) == [1, 2, 3, 4, 5, 6]

log "peekSTArray should return Nothing when peeking a value outside the array bounds"
Expand Down Expand Up @@ -106,21 +106,21 @@ testArrayST = do

assert $ run (do
arr <- thaw [1]
pokeSTArray arr 0 10
void $ pokeSTArray arr 0 10
pure arr) == [10]

log "pokeSTArray should do nothing when attempting to modify a value outside the array bounds"

assert $ run (do
arr <- thaw [1]
pokeSTArray arr 1 2
void $ pokeSTArray arr 1 2
pure arr) == [1]

log "spliceSTArray should be able to delete multiple items at a specified index"

assert $ run (do
arr <- thaw [1, 2, 3, 4, 5]
spliceSTArray arr 1 3 []
void $ spliceSTArray arr 1 3 []
pure arr) == [1, 5]

log "spliceSTArray should return the items removed"
Expand All @@ -133,14 +133,14 @@ testArrayST = do

assert $ run (do
arr <- thaw [1, 2, 3, 4, 5]
spliceSTArray arr 1 0 [0, 100]
void $ spliceSTArray arr 1 0 [0, 100]
pure arr) == [1, 0, 100, 2, 3, 4, 5]

log "spliceSTArray should be able to delete and insert at the same time"

assert $ run (do
arr <- thaw [1, 2, 3, 4, 5]
spliceSTArray arr 1 2 [0, 100]
void $ spliceSTArray arr 1 2 [0, 100]
pure arr) == [1, 0, 100, 4, 5]

log "toAssocArray should return all items in the array with the correct indices and values"
Expand Down
2 changes: 1 addition & 1 deletion test/Test/Main.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Test.Main where

import Prelude (bind, Unit)
import Prelude

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE)
Expand Down