diff --git a/.gitignore b/.gitignore index a392858..e306283 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ +/.* +!/.gitignore +!/.jscsrc +!/.jshintrc +!/.travis.yml /bower_components/ /node_modules/ /output/ -/tmp/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 7b3bb98..7f976a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,15 @@ language: node_js -sudo: false -node_js: - - 0.12.7 +dist: trusty +sudo: required +node_js: 6 install: - - npm install bower -g + - npm install -g bower - npm install - - bower install script: - - pulp build + - bower install --production + - npm run -s build +after_success: +- >- + test $TRAVIS_TAG && + echo $GITHUB_TOKEN | pulp login && + echo y | pulp publish --no-push diff --git a/README.md b/README.md index d3eb521..d85a300 100755 --- a/README.md +++ b/README.md @@ -1,17 +1,16 @@ -# PureScript-Machines +# purescript-machines -This library helps you build finite state machines. Currently, there's an implementation for mealy machines with halting. +[![Latest release](http://img.shields.io/bower/v/purescript-machines.svg)](https://github.com/purescript-contrib/purescript-machines/releases) +[![Build Status](https://travis-ci.org/purescript-contrib/purescript-machines.svg?branch=master)](https://travis-ci.org/purescript-contrib/purescript-machines) -**Note**: If you need the ability to produce errors, consume from multiple input tapes, or guarantee resource cleanup, you should probably be using [PureScript Streams](http://github.com/purescript-contrib/purescript-streams) instead. +This library helps you build finite state machines. Currently, there's an implementation for Mealy machines with halting. ## Installation -This can be installed with Bower: - ```shell bower i purescript-machines ``` ## Documentation -API docs can be found [here](docs/Data/Machine/Mealy.md). +Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-machines). diff --git a/bower.json b/bower.json index 9a68ddc..ecfc56a 100644 --- a/bower.json +++ b/bower.json @@ -10,14 +10,12 @@ }, "license": "MIT", "dependencies": { - "purescript-eff": "~0.1.0", - "purescript-maybe": "~0.3.2", - "purescript-monoid": "~0.3.0", - "purescript-profunctor": "~0.3.0", - "purescript-tuples": "~0.4.0", - "purescript-arrays": "~0.4.0", - "purescript-arrows": "~0.6.0", - "purescript-prelude": "~0.1.0", - "purescript-lists": "~0.7.0" + "purescript-arrays": "^1.0.0", + "purescript-eff": "^1.0.0", + "purescript-lists": "^1.0.0", + "purescript-maybe": "^1.0.0", + "purescript-monoid": "^1.0.0", + "purescript-profunctor": "^1.0.0", + "purescript-tuples": "^1.0.0" } } diff --git a/docs/Data/Machine/Mealy.md b/docs/Data/Machine/Mealy.md deleted file mode 100644 index 5fa3206..0000000 --- a/docs/Data/Machine/Mealy.md +++ /dev/null @@ -1,178 +0,0 @@ -## Module Data.Machine.Mealy - -#### `MealyT` - -``` purescript -newtype MealyT f s a -``` - -##### Instances -``` purescript -instance functorMealy :: (Monad f) => Functor (MealyT f s) -instance applyMealy :: (Monad f) => Apply (MealyT f s) -instance applicativeMealy :: (Monad f) => Applicative (MealyT f s) -instance profunctorMealy :: (Monad f) => Profunctor (MealyT f) -instance strongMealy :: (Monad f) => Strong (MealyT f) -instance semigroupMealy :: (Monad f) => Semigroup (MealyT f s a) -instance monoidMealy :: (Monad f) => Monoid (MealyT f s a) -instance semigroupoidMealy :: (Monad f) => Semigroupoid (MealyT f) -instance categoryMealy :: (Monad f) => Category (MealyT f) -instance arrowMealy :: (Monad f) => Arrow (MealyT f) -instance bindMealy :: (Monad f) => Bind (MealyT f s) -instance monadMealy :: (Monad f) => Monad (MealyT f s) -instance altMealy :: (Monad f) => Alt (MealyT f s) -instance plusMealy :: (Monad f) => Plus (MealyT f s) -instance alternativeMealy :: (Monad f) => Alternative (MealyT f s) -instance monadPlus :: (Monad f) => MonadPlus (MealyT f s) -instance monadEffMealy :: (Monad f, MonadEff eff f) => MonadEff eff (MealyT f s) -``` - -#### `Step` - -``` purescript -data Step f s a - = Emit a (MealyT f s a) - | Halt -``` - -#### `Source` - -``` purescript -type Source f s = MealyT f Unit s -``` - -#### `Sink` - -``` purescript -type Sink f a = MealyT f a Unit -``` - -#### `source` - -``` purescript -source :: forall f s. (Monad f) => f s -> Source f s -``` - -#### `sink` - -``` purescript -sink :: forall f a. (Monad f) => (a -> f Unit) -> Sink f a -``` - -#### `runMealy` - -``` purescript -runMealy :: forall f. (Monad f) => MealyT f Unit Unit -> f Unit -``` - -#### `stepMealy` - -``` purescript -stepMealy :: forall f s a. (Monad f) => s -> MealyT f s a -> f (Step f s a) -``` - -#### `pureMealy` - -``` purescript -pureMealy :: forall f s a. (Applicative f) => (s -> Step f s a) -> MealyT f s a -``` - -#### `mealy` - -``` purescript -mealy :: forall f s a. (Applicative f) => (s -> f (Step f s a)) -> MealyT f s a -``` - -#### `halt` - -``` purescript -halt :: forall f s a. (Applicative f) => MealyT f s a -``` - -#### `take` - -``` purescript -take :: forall f s a. (Monad f) => Int -> MealyT f s a -> MealyT f s a -``` - -#### `drop` - -``` purescript -drop :: forall f s a. (Monad f) => Int -> MealyT f s a -> MealyT f s a -``` - -#### `loop` - -``` purescript -loop :: forall f s a. (Monad f) => MealyT f s a -> MealyT f s a -``` - -#### `zipWith` - -``` purescript -zipWith :: forall f s a b c. (Monad f) => (a -> b -> c) -> MealyT f s a -> MealyT f s b -> MealyT f s c -``` - -#### `scanl` - -``` purescript -scanl :: forall f s a b. (Monad f) => (b -> a -> b) -> b -> MealyT f s a -> MealyT f s b -``` - -#### `collect` - -``` purescript -collect :: forall f s a. (Monad f) => MealyT f s a -> MealyT f s (List a) -``` - -#### `singleton` - -``` purescript -singleton :: forall f s a. (Monad f) => a -> MealyT f s a -``` - -#### `fromMaybe` - -``` purescript -fromMaybe :: forall f s a. (Monad f) => Maybe a -> MealyT f s a -``` - -#### `fromArray` - -``` purescript -fromArray :: forall f s a. (Monad f) => Array a -> MealyT f s a -``` - -#### `wrapEffect` - -``` purescript -wrapEffect :: forall f s a. (Monad f) => f a -> MealyT f s a -``` - -#### `msplit` - -``` purescript -msplit :: forall f s a. (Monad f) => MealyT f s a -> MealyT f s (Maybe (Tuple a (MealyT f s a))) -``` - -#### `interleave` - -``` purescript -interleave :: forall f s a. (Monad f) => MealyT f s a -> MealyT f s a -> MealyT f s a -``` - -#### `ifte` - -``` purescript -ifte :: forall f s a b. (Monad f) => MealyT f s a -> (a -> MealyT f s b) -> MealyT f s b -> MealyT f s b -``` - -#### `(>>-)` - -``` purescript -(>>-) :: forall f s a b. (Monad f) => MealyT f s a -> (a -> MealyT f s b) -> MealyT f s b -``` - -_left-associative / precedence -1_ - - diff --git a/package.json b/package.json index d601d63..5586ac1 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,12 @@ { - "name": "purescript-machines", - "description": "Mealy Machines in PureScript", - "license": "MIT", + "private": true, + "scripts": { + "clean": "rimraf output && rimraf .pulp-cache", + "build": "psa \"src/**/*.purs\" \"bower_components/purescript-*/src/**/*.purs\" --censor-lib --strict" + }, "devDependencies": { - "pulp": "^4.4.0", - "purescript": "^0.7.4" + "purescript-psa": "^0.3.8", + "purescript": "^0.9.1-rc.1", + "rimraf": "^2.5.0" } } diff --git a/src/Data/Machine/Mealy.purs b/src/Data/Machine/Mealy.purs index df4aaf9..298c97d 100644 --- a/src/Data/Machine/Mealy.purs +++ b/src/Data/Machine/Mealy.purs @@ -1,9 +1,9 @@ module Data.Machine.Mealy - ( MealyT() + ( MealyT , runMealyT , Step(..) - , Source() - , Sink() + , Source + , Sink , source , sink , stepMealy @@ -22,26 +22,27 @@ module Data.Machine.Mealy , fromArray , msplit , interleave - , (>>-) + , when , ifte , wrapEffect ) where import Prelude -import Control.Alt (Alt) -import Control.Alternative (Alternative) -import Control.Arrow (Arrow) -import Control.Bind (join) -import Control.Lazy (Lazy) -import Control.MonadPlus (MonadPlus) -import Control.Plus (Plus) -import Control.Monad.Eff.Class (MonadEff, liftEff) + +import Control.Alt (class Alt) +import Control.Alternative (class Alternative) +import Control.Lazy (class Lazy) +import Control.Monad.Eff.Class (class MonadEff, liftEff) +import Control.MonadPlus (class MonadPlus) +import Control.MonadZero (class MonadZero) +import Control.Plus (class Plus) + import Data.Array ((!!), length) import Data.List (List(..)) import Data.Maybe (Maybe(..)) -import Data.Monoid (Monoid) -import Data.Profunctor (Profunctor, dimap) -import Data.Profunctor.Strong (Strong, first) +import Data.Monoid (class Monoid) +import Data.Profunctor (class Profunctor, dimap) +import Data.Profunctor.Strong (class Strong, first) import Data.Tuple (Tuple(..), fst, snd, swap) newtype MealyT f s a = MealyT (f (s -> f (Step f s a))) @@ -149,8 +150,8 @@ ifte ma f mb = mealy $ \s -> let g Halt = stepMealy s mb in stepMealy s ma >>= g -(>>-) :: forall f s a b. (Monad f) => MealyT f s a -> (a -> MealyT f s b) -> MealyT f s b -(>>-) ma f = ifte ma f halt +when :: forall f s a b. (Monad f) => MealyT f s a -> (a -> MealyT f s b) -> MealyT f s b +when ma f = ifte ma f halt instance functorMealy :: (Monad f) => Functor (MealyT f s) where map f m = mealy $ \s -> g <$> stepMealy s m where @@ -200,8 +201,6 @@ instance semigroupoidMealy :: (Monad f) => Semigroupoid (MealyT f) where instance categoryMealy :: (Monad f) => Category (MealyT f) where id = pureMealy $ \t -> Emit t halt -instance arrowMealy :: (Monad f) => Arrow (MealyT f) - instance bindMealy :: (Monad f) => Bind (MealyT f s) where bind m f = mealy $ \s -> let g (Emit a m') = h <$> stepMealy s (f a) where @@ -222,10 +221,12 @@ instance plusMealy :: (Monad f) => Plus (MealyT f s) where instance alternativeMealy :: (Monad f) => Alternative (MealyT f s) +instance monadZero :: (Monad f) => MonadZero (MealyT f s) + instance monadPlus :: (Monad f) => MonadPlus (MealyT f s) instance monadEffMealy :: (Monad f, MonadEff eff f) => MonadEff eff (MealyT f s) where liftEff = wrapEffect <<< liftEff instance lazyMealy :: (Monad f) => Lazy (MealyT f s a) where - defer f = mealy \s -> runMealyT (f unit) >>= ($ s) + defer f = mealy \s -> runMealyT (f unit) >>= (_ $ s)