diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e0e5df0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: CI + +jobs: + build: + runs-on: ubuntu-latest + + steps: + # SETUP + - uses: actions/checkout@v2 + + - uses: thomashoneyman/setup-purescript@main + with: + purescript: "0.14.5" + spago: "0.20.3" + zephyr: "0.3.2" + purs-tidy: "0.6.4" + + - name: Cache PureScript dependencies + uses: actions/cache@v2 + with: + key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }} + path: | + .spago + output + - uses: actions/setup-node@v2 + with: + node-version: "16.x" + cache: "npm" + + # - name: Install NPM dependencies + # run: npm ci + + - name: Build source + run: spago build + + - name: Run tests + run: spago test --no-install + + - name: Check formatting + run: purs-tidy check src test + + # - name: Run bundle + # run: npm run bundle + + # - name: Deploy to GitHub Pages + # uses: peaceiris/actions-gh-pages@v3 + # with: + # github_token: ${{ secrets.GITHUB_TOKEN }} + # publish_dir: ./dist + # if: github.event_name == 'push' && github.ref == 'refs/heads/main' diff --git a/.gitignore b/.gitignore index d7d596d..635a870 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ bower_components/ output/ +.spago/ +.purs-repl diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index dbf4082..0000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -language: node_js -sudo: false -node_js: - - node -env: - - PATH=$HOME/purescript:$PATH -install: -- 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') -- 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 bower pulp -g -- bower install -script: - - pulp test && pulp docs - -after_success: - - >- - test $TRAVIS_TAG && - psc-publish \ - | tail -n 1 \ - > output/documentation.json && - curl -X POST http://pursuit.purescript.org/packages \ - -d @output/documentation.json \ - -H 'Accept: application/json' \ - -H "Authorization: token ${GITHUB_TOKEN}" diff --git a/bower.json b/bower.json deleted file mode 100644 index 92c2491..0000000 --- a/bower.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "purescript-var", - "description": "Vars -- references that can be read/written from the Eff monad", - "authors": [ - "Konstantin Zudov " - ], - "license": "BSD-3-Clause", - "moduleType": [ - "node" - ], - "repository": { - "type": "git", - "url": "git://github.com/zudov/purescript-var.git" - }, - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "output" - ], - "keywords": [ - "purescript" - ], - "dependencies": { - "purescript-effect": "^2.0.0", - "purescript-contravariant": "^4.0.0", - "purescript-invariant": "^4.0.0" - }, - "devDependencies": { - "purescript-console": "^4.1.0", - "purescript-psci-support": "^4.0.0" - } -} diff --git a/packages.dhall b/packages.dhall new file mode 100644 index 0000000..f7039f1 --- /dev/null +++ b/packages.dhall @@ -0,0 +1,104 @@ +{- +Welcome to your new Dhall package-set! + +Below are instructions for how to edit this file for most use +cases, so that you don't need to know Dhall to use it. + +## Use Cases + +Most will want to do one or both of these options: +1. Override/Patch a package's dependency +2. Add a package not already in the default package set + +This file will continue to work whether you use one or both options. +Instructions for each option are explained below. + +### Overriding/Patching a package + +Purpose: +- Change a package's dependency to a newer/older release than the + default package set's release +- Use your own modified version of some dependency that may + include new API, changed API, removed API by + using your custom git repo of the library rather than + the package set's repo + +Syntax: +where `entityName` is one of the following: +- dependencies +- repo +- version +------------------------------- +let upstream = -- +in upstream + with packageName.entityName = "new value" +------------------------------- + +Example: +------------------------------- +let upstream = -- +in upstream + with halogen.version = "master" + with halogen.repo = "https://example.com/path/to/git/repo.git" + + with halogen-vdom.version = "v4.0.0" + with halogen-vdom.dependencies = [ "extra-dependency" ] # halogen-vdom.dependencies +------------------------------- + +### Additions + +Purpose: +- Add packages that aren't already included in the default package set + +Syntax: +where `` is: +- a tag (i.e. "v4.0.0") +- a branch (i.e. "master") +- commit hash (i.e. "701f3e44aafb1a6459281714858fadf2c4c2a977") +------------------------------- +let upstream = -- +in upstream + with new-package-name = + { dependencies = + [ "dependency1" + , "dependency2" + ] + , repo = + "https://example.com/path/to/git/repo.git" + , version = + "" + } +------------------------------- + +Example: +------------------------------- +let upstream = -- +in upstream + with benchotron = + { dependencies = + [ "arrays" + , "exists" + , "profunctor" + , "strings" + , "quickcheck" + , "lcg" + , "transformers" + , "foldable-traversable" + , "exceptions" + , "node-fs" + , "node-buffer" + , "node-readline" + , "datetime" + , "now" + ] + , repo = + "https://github.com/hdgarrood/purescript-benchotron.git" + , version = + "v7.0.0" + } +------------------------------- +-} +let upstream = + https://github.com/purescript/package-sets/releases/download/psc-0.14.5-20220110/packages.dhall sha256:8dbf71bfc6c7a11043619eebe90ff85f7d884541048aa8cc48eef1ee781cbc0e + +in upstream diff --git a/spago.dhall b/spago.dhall new file mode 100644 index 0000000..12ee00b --- /dev/null +++ b/spago.dhall @@ -0,0 +1,14 @@ +{ name = "var" +, dependencies = [ + "console", + "effect", + "prelude", + "psci-support", + "contravariant", + "invariant", + "either", + "tuples" +] +, packages = ./packages.dhall +, sources = [ "src/**/*.purs", "test/**/*.purs" ] +} diff --git a/src/Control/Monad/Eff/Var.purs b/src/Control/Monad/Eff/Var.purs index b669547..07997e3 100644 --- a/src/Control/Monad/Eff/Var.purs +++ b/src/Control/Monad/Eff/Var.purs @@ -1,16 +1,15 @@ -- | `Var`s allow to provide a uniform read/write access to the references in --- | the `Eff` monad. This is mostly useful when making low-level FFI bindings. +-- | the `Effect` monad. This is mostly useful when making low-level FFI bindings. -- | For example we might have some global counter with the following API: -- | ```purescript --- | foreign import data COUNT :: ! --- | getCounter :: forall eff. Eff (count :: COUNT | eff) Int --- | setCounter :: forall eff. Int -> Eff (count :: COUNT | eff) Unit +-- | getCounter :: Effect Int +-- | setCounter :: Int -> Effect Unit -- | ``` -- | -- | `getCounter` and `setCounter` can be kept together in a `Var`: -- | ```purescript --- | counter :: forall eff. Var (count :: COUNT | eff) Int +-- | counter :: Var Int -- | counter = makeVar getCounter setCounter -- | ``` -- | @@ -42,7 +41,7 @@ module Effect.Var , makeSettableVar ) where -import Prelude +import Prelude import Effect (Effect) import Data.Decidable (class Decidable) @@ -74,20 +73,20 @@ infixr 2 update as $~ -- | Read/Write var which holds a value of type `a` and produces effects `eff` -- | when read or written. -newtype Var a - = Var { gettable :: GettableVar a - , settable :: SettableVar a - } +newtype Var a = Var + { gettable :: GettableVar a + , settable :: SettableVar a + } -- | Create a `Var` from getter and setter. makeVar :: forall a. Effect a -> (a -> Effect Unit) -> Var a makeVar g s = Var { gettable, settable } where - gettable = makeGettableVar g - settable = makeSettableVar s + gettable = makeGettableVar g + settable = makeSettableVar s instance settableVar :: Settable Var a where - set (Var { settable } ) = set settable + set (Var { settable }) = set settable instance gettableVar :: Gettable Var a where get (Var { gettable }) = get gettable @@ -95,10 +94,11 @@ instance gettableVar :: Gettable Var a where instance updatableVar :: Updatable Var a where update v f = get v >>= f >>> set v -instance invariantVar :: Invariant Var where - imap ab ba (Var v) = Var { gettable: ab <$> v.gettable - , settable: ba >$< v.settable - } +instance invariantVar :: Invariant Var where + imap ab ba (Var v) = Var + { gettable: ab <$> v.gettable + , settable: ba >$< v.settable + } -- | Read-only var which holds a value of type `a` and produces effects `eff` -- | when read. @@ -128,7 +128,7 @@ newtype SettableVar a = SettableVar (a -> Effect Unit) makeSettableVar :: forall a. (a -> Effect Unit) -> SettableVar a makeSettableVar = SettableVar -instance settableSettableVar :: Settable SettableVar a where +instance settableSettableVar :: Settable SettableVar a where set (SettableVar action) = action instance contravariantSettableVar :: Contravariant SettableVar where @@ -148,5 +148,5 @@ instance decideSettableVar :: Decide SettableVar where choose f (SettableVar setb) (SettableVar setc) = SettableVar (either setb setc <<< f) instance decidableSettableVar :: Decidable SettableVar where --- lose :: forall a. (a -> Void) -> f a + -- lose :: forall a. (a -> Void) -> f a lose f = SettableVar (absurd <<< f) diff --git a/test/Main.purs b/test/Main.purs index 9861341..4c3f623 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -13,11 +13,11 @@ counter = makeVar getCounter setCounter main :: Effect Unit main = do - counter $= 0 -- set counter to 0 + counter $= 0 -- set counter to 0 get counter >>= print -- => 0 - counter $= 2 -- set counter to 2 + counter $= 2 -- set counter to 2 get counter >>= print -- => 2 - counter $~ (_ * 5) -- multiply counter by 5 + counter $~ (_ * 5) -- multiply counter by 5 get counter >>= print -- => 10 print :: forall a. Show a => a -> Effect Unit