From 5843d726abc6997012f3ecbefeb4f6c6b7d38e83 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sun, 17 Jan 2016 17:05:21 +0000 Subject: [PATCH] Updates for PureScript 0.8 --- .gitignore | 1 - .jscsrc | 5 ++ .jshintrc | 5 +- .travis.yml | 11 +++- README.md | 8 ++- bower.json | 6 +-- docs/Control/Monad/Eff.md | 85 ------------------------------- docs/Control/Monad/Eff/Class.md | 26 ---------- docs/Control/Monad/Eff/Unsafe.md | 22 -------- package.json | 11 ++-- src/Control/Monad/Eff.js | 3 +- src/Control/Monad/Eff.purs | 65 +++++++++++++---------- src/Control/Monad/Eff/Class.purs | 27 +++++----- src/Control/Monad/Eff/Unsafe.js | 1 - src/Control/Monad/Eff/Unsafe.purs | 20 +++++--- 15 files changed, 93 insertions(+), 203 deletions(-) delete mode 100644 docs/Control/Monad/Eff.md delete mode 100644 docs/Control/Monad/Eff/Class.md delete mode 100644 docs/Control/Monad/Eff/Unsafe.md diff --git a/.gitignore b/.gitignore index 748273b..e306283 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,3 @@ /bower_components/ /node_modules/ /output/ -/tmp/ diff --git a/.jscsrc b/.jscsrc index 342da66..2561ce9 100644 --- a/.jscsrc +++ b/.jscsrc @@ -1,5 +1,10 @@ { "preset": "grunt", + "disallowSpacesInFunctionExpression": null, + "requireSpacesInFunctionExpression": { + "beforeOpeningRoundBrace": true, + "beforeOpeningCurlyBrace": true + }, "disallowSpacesInAnonymousFunctionExpression": null, "requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, diff --git a/.jshintrc b/.jshintrc index f391159..620d8d7 100644 --- a/.jshintrc +++ b/.jshintrc @@ -5,7 +5,7 @@ "freeze": true, "funcscope": true, "futurehostile": true, - "globalstrict": true, + "strict": "global", "latedef": true, "maxparams": 1, "noarg": true, @@ -15,5 +15,6 @@ "singleGroups": true, "undef": true, "unused": true, - "eqnull": true + "eqnull": true, + "predef": ["exports"] } diff --git a/.travis.yml b/.travis.yml index 791313a..851998b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js sudo: false node_js: - - 0.10 + - 5 env: - PATH=$HOME/purescript:$PATH install: @@ -9,6 +9,15 @@ install: - wget -O $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 + - npm install -g bower - npm install script: - npm run build +after_success: +- >- + test $TRAVIS_TAG && + psc-publish > .pursuit.json && + curl -X POST http://pursuit.purescript.org/packages \ + -d @.pursuit.json \ + -H 'Accept: application/json' \ + -H "Authorization: token ${GITHUB_TOKEN}" diff --git a/README.md b/README.md index 8aaa5d6..3b4cea9 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Build Status](https://travis-ci.org/purescript/purescript-eff.svg?branch=master)](https://travis-ci.org/purescript/purescript-eff) [![Dependency Status](https://www.versioneye.com/user/projects/55848cde3638610015000408/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55848cde3638610015000408) -The `Eff` monad, for handling native side effects. For use with compiler version >= 0.7. +The `Eff` monad, for handling native side effects. ## Installation @@ -12,8 +12,6 @@ The `Eff` monad, for handling native side effects. For use with compiler version bower install purescript-eff ``` -## Module documentation +## Documentation -- [Control.Monad.Eff](docs/Control/Monad/Eff.md) -- [Control.Monad.Eff.Unsafe](docs/Control/Monad/Eff/Unsafe.md) -- [Control.Monad.Eff.Class](docs/Control/Monad/Eff/Class.md) +Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-eff). diff --git a/bower.json b/bower.json index 27b9577..baabe61 100644 --- a/bower.json +++ b/bower.json @@ -2,9 +2,6 @@ "name": "purescript-eff", "homepage": "https://github.com/purescript/purescript-eff", "description": "The Eff monad, for handling native side effects", - "keywords": [ - "purescript" - ], "license": "MIT", "repository": { "type": "git", @@ -17,10 +14,9 @@ "output", "test", "bower.json", - "gulpfile.js", "package.json" ], "dependencies": { - "purescript-prelude": "^0.1.0" + "purescript-prelude": "^1.0.0-rc.1" } } diff --git a/docs/Control/Monad/Eff.md b/docs/Control/Monad/Eff.md deleted file mode 100644 index 3b75387..0000000 --- a/docs/Control/Monad/Eff.md +++ /dev/null @@ -1,85 +0,0 @@ -## Module Control.Monad.Eff - -#### `Eff` - -``` purescript -data Eff :: # ! -> * -> * -``` - -The `Eff` type constructor is used to represent _native_ effects. - -See [Handling Native Effects with the Eff Monad](http://www.purescript.org/learn/eff/) for more details. - -The first type parameter is a row of effects which represents the contexts in which a computation can be run, and the second type parameter is the return type. - -##### Instances -``` purescript -instance functorEff :: Functor (Eff e) -instance applyEff :: Apply (Eff e) -instance applicativeEff :: Applicative (Eff e) -instance bindEff :: Bind (Eff e) -instance monadEff :: Monad (Eff e) -``` - -#### `Pure` - -``` purescript -type Pure a = Eff () a -``` - -The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled. - -The `runPure` function can be used to run pure computations and obtain their result. - -#### `runPure` - -``` purescript -runPure :: forall a. Pure a -> a -``` - -Run a pure computation and return its result. - -#### `untilE` - -``` purescript -untilE :: forall e. Eff e Boolean -> Eff e Unit -``` - -Loop until a condition becomes `true`. - -`untilE b` is an effectful computation which repeatedly runs the effectful computation `b`, -until its return value is `true`. - -#### `whileE` - -``` purescript -whileE :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit -``` - -Loop while a condition is `true`. - -`whileE b m` is effectful computation which runs the effectful computation `b`. If its result is -`true`, it runs the effectful computation `m` and loops. If not, the computation ends. - -#### `forE` - -``` purescript -forE :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit -``` - -Loop over a consecutive collection of numbers. - -`forE lo hi f` runs the computation returned by the function `f` for each of the inputs -between `lo` (inclusive) and `hi` (exclusive). - -#### `foreachE` - -``` purescript -foreachE :: forall e a. Array a -> (a -> Eff e Unit) -> Eff e Unit -``` - -Loop over an array of values. - -`foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`. - - diff --git a/docs/Control/Monad/Eff/Class.md b/docs/Control/Monad/Eff/Class.md deleted file mode 100644 index fbfd2ce..0000000 --- a/docs/Control/Monad/Eff/Class.md +++ /dev/null @@ -1,26 +0,0 @@ -## Module Control.Monad.Eff.Class - -#### `MonadEff` - -``` purescript -class (Monad m) <= MonadEff eff m where - liftEff :: forall a. Eff eff a -> m a -``` - -The `MonadEff` class captures those monads which support native effects. - -Instances are provided for `Eff` itself, and the standard monad transformers. - -`liftEff` can be used in any appropriate monad transformer stack to lift an action -of type `Eff eff a` into the monad. - -Note that `MonadEff` is parameterized by the row of effects, so type inference can be -tricky. It is generally recommended to either work with a polymorphic row of effects, -or a concrete, closed row of effects such as `(trace :: Trace)`. - -##### Instances -``` purescript -instance monadEffEff :: MonadEff eff (Eff eff) -``` - - diff --git a/docs/Control/Monad/Eff/Unsafe.md b/docs/Control/Monad/Eff/Unsafe.md deleted file mode 100644 index e6b123a..0000000 --- a/docs/Control/Monad/Eff/Unsafe.md +++ /dev/null @@ -1,22 +0,0 @@ -## Module Control.Monad.Eff.Unsafe - -#### `unsafeInterleaveEff` - -``` purescript -unsafeInterleaveEff :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a -``` - -Change the type of an effectful computation, allowing it to be run in another context. - -Note: use of this function can result in arbitrary side-effects. - -#### `unsafePerformEff` - -``` purescript -unsafePerformEff :: forall eff a. Eff eff a -> a -``` - -Run an effectful computation. Note: use of this function can result in -arbitrary side-effects. - - diff --git a/package.json b/package.json index 61f11c6..b326108 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,13 @@ "private": true, "scripts": { "postinstall": "pulp dep install", - "build": "jshint src && jscs src && pulp build && rimraf docs && pulp docs" + "clean": "rimraf output && rimraf .pulp-cache", + "build": "jshint src && jscs src && pulp build" }, "devDependencies": { - "jscs": "^1.13.1", - "jshint": "^2.8.0", - "pulp": "^4.0.1", - "rimraf": "^2.4.1" + "jscs": "^2.8.0", + "jshint": "^2.9.1", + "pulp": "^8.0.0", + "rimraf": "^2.5.0" } } diff --git a/src/Control/Monad/Eff.js b/src/Control/Monad/Eff.js index 1498f21..af32693 100644 --- a/src/Control/Monad/Eff.js +++ b/src/Control/Monad/Eff.js @@ -1,9 +1,8 @@ -/* global exports */ "use strict"; // module Control.Monad.Eff -exports.returnE = function (a) { +exports.pureE = function (a) { return function () { return a; }; diff --git a/src/Control/Monad/Eff.purs b/src/Control/Monad/Eff.purs index a14c955..425407e 100644 --- a/src/Control/Monad/Eff.purs +++ b/src/Control/Monad/Eff.purs @@ -1,31 +1,28 @@ module Control.Monad.Eff - ( Eff() - , Pure() + ( Eff + , Pure , runPure , untilE, whileE, forE, foreachE ) where -import Prelude +import Control.Applicative (class Applicative, liftA1) +import Control.Apply (class Apply) +import Control.Bind (class Bind) +import Control.Monad (class Monad, ap) + +import Data.Functor (class Functor) +import Data.Unit (Unit) -- | The `Eff` type constructor is used to represent _native_ effects. -- | --- | See [Handling Native Effects with the Eff Monad](http://www.purescript.org/learn/eff/) for more details. +-- | See [Handling Native Effects with the Eff Monad](http://www.purescript.org/learn/eff/) +-- | for more details. -- | --- | The first type parameter is a row of effects which represents the contexts in which a computation can be run, and the second type parameter is the return type. +-- | The first type parameter is a row of effects which represents the contexts +-- | in which a computation can be run, and the second type parameter is the +-- | return type. foreign import data Eff :: # ! -> * -> * -foreign import returnE :: forall e a. a -> Eff e a - -foreign import bindE :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b - --- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled. --- | --- | The `runPure` function can be used to run pure computations and obtain their result. -type Pure a = Eff () a - --- | Run a pure computation and return its result. -foreign import runPure :: forall a. Pure a -> a - instance functorEff :: Functor (Eff e) where map = liftA1 @@ -33,32 +30,48 @@ instance applyEff :: Apply (Eff e) where apply = ap instance applicativeEff :: Applicative (Eff e) where - pure = returnE + pure = pureE + +foreign import pureE :: forall e a. a -> Eff e a instance bindEff :: Bind (Eff e) where bind = bindE +foreign import bindE :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b + instance monadEff :: Monad (Eff e) +-- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which +-- | all effects have been handled. +-- | +-- | The `runPure` function can be used to run pure computations and obtain +-- | their result. +type Pure a = Eff () a + +-- | Run a pure computation and return its result. +foreign import runPure :: forall a. Pure a -> a + -- | Loop until a condition becomes `true`. -- | --- | `untilE b` is an effectful computation which repeatedly runs the effectful computation `b`, --- | until its return value is `true`. +-- | `untilE b` is an effectful computation which repeatedly runs the effectful +-- | computation `b`, until its return value is `true`. foreign import untilE :: forall e. Eff e Boolean -> Eff e Unit -- | Loop while a condition is `true`. -- | --- | `whileE b m` is effectful computation which runs the effectful computation `b`. If its result is --- | `true`, it runs the effectful computation `m` and loops. If not, the computation ends. +-- | `whileE b m` is effectful computation which runs the effectful computation +-- | `b`. If its result is `true`, it runs the effectful computation `m` and +-- | loops. If not, the computation ends. foreign import whileE :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit -- | Loop over a consecutive collection of numbers. -- | --- | `forE lo hi f` runs the computation returned by the function `f` for each of the inputs --- | between `lo` (inclusive) and `hi` (exclusive). -foreign import forE :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit +-- | `forE lo hi f` runs the computation returned by the function `f` for each +-- | of the inputs between `lo` (inclusive) and `hi` (exclusive). +foreign import forE :: forall e. Int -> Int -> (Int -> Eff e Unit) -> Eff e Unit -- | Loop over an array of values. -- | --- | `foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`. +-- | `foreach xs f` runs the computation returned by the function `f` for each +-- | of the inputs `xs`. foreign import foreachE :: forall e a. Array a -> (a -> Eff e Unit) -> Eff e Unit diff --git a/src/Control/Monad/Eff/Class.purs b/src/Control/Monad/Eff/Class.purs index dbfd58e..6c55965 100644 --- a/src/Control/Monad/Eff/Class.purs +++ b/src/Control/Monad/Eff/Class.purs @@ -1,23 +1,22 @@ -module Control.Monad.Eff.Class - ( MonadEff - , liftEff - ) where +module Control.Monad.Eff.Class where -import Prelude - -import Control.Monad.Eff +import Control.Category (id) +import Control.Monad (class Monad) +import Control.Monad.Eff (Eff) -- | The `MonadEff` class captures those monads which support native effects. -- | --- | Instances are provided for `Eff` itself, and the standard monad transformers. +-- | Instances are provided for `Eff` itself, and the standard monad +-- | transformers. -- | --- | `liftEff` can be used in any appropriate monad transformer stack to lift an action --- | of type `Eff eff a` into the monad. +-- | `liftEff` can be used in any appropriate monad transformer stack to lift an +-- | action of type `Eff eff a` into the monad. -- | --- | Note that `MonadEff` is parameterized by the row of effects, so type inference can be --- | tricky. It is generally recommended to either work with a polymorphic row of effects, --- | or a concrete, closed row of effects such as `(trace :: Trace)`. -class (Monad m) <= MonadEff eff m where +-- | Note that `MonadEff` is parameterized by the row of effects, so type +-- | inference can be tricky. It is generally recommended to either work with a +-- | polymorphic row of effects, or a concrete, closed row of effects such as +-- | `(trace :: Trace)`. +class Monad m <= MonadEff eff m where liftEff :: forall a. Eff eff a -> m a instance monadEffEff :: MonadEff eff (Eff eff) where diff --git a/src/Control/Monad/Eff/Unsafe.js b/src/Control/Monad/Eff/Unsafe.js index bada18a..b24421f 100644 --- a/src/Control/Monad/Eff/Unsafe.js +++ b/src/Control/Monad/Eff/Unsafe.js @@ -1,4 +1,3 @@ -/* global exports */ "use strict"; // module Control.Monad.Eff.Unsafe diff --git a/src/Control/Monad/Eff/Unsafe.purs b/src/Control/Monad/Eff/Unsafe.purs index 29f26fc..3edb6d2 100644 --- a/src/Control/Monad/Eff/Unsafe.purs +++ b/src/Control/Monad/Eff/Unsafe.purs @@ -1,15 +1,19 @@ module Control.Monad.Eff.Unsafe where -import Prelude +import Control.Monad.Eff (Eff, runPure) +import Control.Semigroupoid ((<<<)) -import Control.Monad.Eff - --- | Change the type of an effectful computation, allowing it to be run in another context. +-- | Change the type of an effectful computation, allowing it to be run in +-- | another context. -- | --- | Note: use of this function can result in arbitrary side-effects. -foreign import unsafeInterleaveEff :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a +-- | *Note*: use of this function can result in arbitrary side-effects. +foreign import unsafeInterleaveEff + :: forall eff1 eff2 a + . Eff eff1 a + -> Eff eff2 a --- | Run an effectful computation. Note: use of this function can result in --- | arbitrary side-effects. +-- | Run an effectful computation. +-- | +-- | *Note*: use of this function can result in arbitrary side-effects. unsafePerformEff :: forall eff a. Eff eff a -> a unsafePerformEff = runPure <<< unsafeInterleaveEff