From f33d0d6d8e320706aeff30d0dcad40428cf03de3 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sun, 17 Jan 2016 17:06:35 +0000 Subject: [PATCH] Updates for PureScript 0.8 --- .travis.yml | 11 ++++++- README.md | 14 ++------- bower.json | 7 ++--- docs/Data/Monoid.md | 29 ----------------- docs/Data/Monoid/Additive.md | 40 ------------------------ docs/Data/Monoid/Conj.md | 41 ------------------------ docs/Data/Monoid/Disj.md | 41 ------------------------ docs/Data/Monoid/Dual.md | 40 ------------------------ docs/Data/Monoid/Endo.md | 31 ------------------- docs/Data/Monoid/Multiplicative.md | 40 ------------------------ package.json | 7 +++-- src/Data/Monoid.purs | 13 +++++--- src/Data/Monoid/Additive.purs | 48 +++++++++++++++++++---------- src/Data/Monoid/Conj.purs | 43 ++++++++++++++++++-------- src/Data/Monoid/Disj.purs | 41 +++++++++++++++--------- src/Data/Monoid/Dual.purs | 47 ++++++++++++++++++---------- src/Data/Monoid/Endo.purs | 8 ++--- src/Data/Monoid/Multiplicative.purs | 38 ++++++++++++++++------- 18 files changed, 178 insertions(+), 361 deletions(-) delete mode 100644 docs/Data/Monoid.md delete mode 100644 docs/Data/Monoid/Additive.md delete mode 100644 docs/Data/Monoid/Conj.md delete mode 100644 docs/Data/Monoid/Disj.md delete mode 100644 docs/Data/Monoid/Dual.md delete mode 100644 docs/Data/Monoid/Endo.md delete mode 100644 docs/Data/Monoid/Multiplicative.md 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 7179b0a..2766a19 100644 --- a/README.md +++ b/README.md @@ -12,16 +12,6 @@ Monoid algebraic structure. bower install purescript-monoid ``` -## Module documentation +## Documentation -- [Data.Monoid](docs/Data/Monoid.md) -- [Data.Monoid.Dual](docs/Data/Monoid/Dual.md) -- [Data.Monoid.Endo](docs/Data/Monoid/Endo.md) - -### Monoids for semirings -- [Data.Monoid.Additive](docs/Data/Monoid/Additive.md) -- [Data.Monoid.Multiplicative](docs/Data/Monoid/Multiplicative.md) - -### Monoids for boolean algebras -- [Data.Monoid.Conj](docs/Data/Monoid/Conj.md) -- [Data.Monoid.Disj](docs/Data/Monoid/Disj.md) +Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-monoid). diff --git a/bower.json b/bower.json index 4c0d74c..5fe645d 100644 --- a/bower.json +++ b/bower.json @@ -2,9 +2,6 @@ "name": "purescript-monoid", "homepage": "https://github.com/purescript/purescript-monoid", "description": "Monoid algebraic structure", - "keywords": [ - "purescript" - ], "license": "MIT", "repository": { "type": "git", @@ -20,7 +17,7 @@ "package.json" ], "dependencies": { - "purescript-control": "^0.3.0", - "purescript-invariant": "^0.3.0" + "purescript-control": "^1.0.0-rc.1", + "purescript-invariant": "^1.0.0-rc.1" } } diff --git a/docs/Data/Monoid.md b/docs/Data/Monoid.md deleted file mode 100644 index 73b8bac..0000000 --- a/docs/Data/Monoid.md +++ /dev/null @@ -1,29 +0,0 @@ -## Module Data.Monoid - -#### `Monoid` - -``` purescript -class (Semigroup m) <= Monoid m where - mempty :: m -``` - -A `Monoid` is a `Semigroup` with a value `mempty`, which is both a -left and right unit for the associative operation `<>`: - -```text -forall x. mempty <> x = x <> mempty = x -``` - -`Monoid`s are commonly used as the result of fold operations, where -`<>` is used to combine individual results, and `mempty` gives the result -of folding an empty collection of elements. - -##### Instances -``` purescript -instance monoidUnit :: Monoid Unit -instance monoidFn :: (Monoid b) => Monoid (a -> b) -instance monoidString :: Monoid String -instance monoidArray :: Monoid (Array a) -``` - - diff --git a/docs/Data/Monoid/Additive.md b/docs/Data/Monoid/Additive.md deleted file mode 100644 index cf18277..0000000 --- a/docs/Data/Monoid/Additive.md +++ /dev/null @@ -1,40 +0,0 @@ -## Module Data.Monoid.Additive - -#### `Additive` - -``` purescript -newtype Additive a - = Additive a -``` - -Monoid and semigroup for semirings under addition. - -``` purescript -Additive x <> Additive y == Additive (x + y) -mempty :: Additive _ == Additive zero -``` - -##### Instances -``` purescript -instance eqAdditive :: (Eq a) => Eq (Additive a) -instance ordAdditive :: (Ord a) => Ord (Additive a) -instance functorAdditive :: Functor Additive -instance applyAdditive :: Apply Additive -instance applicativeAdditive :: Applicative Additive -instance bindAdditive :: Bind Additive -instance monadAdditive :: Monad Additive -instance extendAdditive :: Extend Additive -instance comonadAdditive :: Comonad Additive -instance invariantAdditive :: Invariant Additive -instance showAdditive :: (Show a) => Show (Additive a) -instance semigroupAdditive :: (Semiring a) => Semigroup (Additive a) -instance monoidAdditive :: (Semiring a) => Monoid (Additive a) -``` - -#### `runAdditive` - -``` purescript -runAdditive :: forall a. Additive a -> a -``` - - diff --git a/docs/Data/Monoid/Conj.md b/docs/Data/Monoid/Conj.md deleted file mode 100644 index b54bd6b..0000000 --- a/docs/Data/Monoid/Conj.md +++ /dev/null @@ -1,41 +0,0 @@ -## Module Data.Monoid.Conj - -#### `Conj` - -``` purescript -newtype Conj a - = Conj a -``` - -Monoid under conjuntion. - -``` purescript -Conj x <> Conj y == Conj (x && y) -mempty :: Conj _ == Conj top -``` - -##### Instances -``` purescript -instance eqConj :: (Eq a) => Eq (Conj a) -instance ordConj :: (Ord a) => Ord (Conj a) -instance boundedConj :: (Bounded a) => Bounded (Conj a) -instance functorConj :: Functor Conj -instance applyConj :: Apply Conj -instance applicativeConj :: Applicative Conj -instance bindConj :: Bind Conj -instance monadConj :: Monad Conj -instance extendConj :: Extend Conj -instance comonadConj :: Comonad Conj -instance showConj :: (Show a) => Show (Conj a) -instance semigroupConj :: (BooleanAlgebra a) => Semigroup (Conj a) -instance monoidConj :: (BooleanAlgebra a) => Monoid (Conj a) -instance semiringConj :: (BooleanAlgebra a) => Semiring (Conj a) -``` - -#### `runConj` - -``` purescript -runConj :: forall a. Conj a -> a -``` - - diff --git a/docs/Data/Monoid/Disj.md b/docs/Data/Monoid/Disj.md deleted file mode 100644 index b0b5ac3..0000000 --- a/docs/Data/Monoid/Disj.md +++ /dev/null @@ -1,41 +0,0 @@ -## Module Data.Monoid.Disj - -#### `Disj` - -``` purescript -newtype Disj a - = Disj a -``` - -Monoid under disjuntion. - -``` purescript -Disj x <> Disj y == Disj (x || y) -mempty :: Disj _ == Disj bottom -``` - -##### Instances -``` purescript -instance eqDisj :: (Eq a) => Eq (Disj a) -instance ordDisj :: (Ord a) => Ord (Disj a) -instance boundedDisj :: (Bounded a) => Bounded (Disj a) -instance functorDisj :: Functor Disj -instance applyDisj :: Apply Disj -instance applicativeDisj :: Applicative Disj -instance bindDisj :: Bind Disj -instance monadDisj :: Monad Disj -instance extendDisj :: Extend Disj -instance comonadDisj :: Comonad Disj -instance showDisj :: (Show a) => Show (Disj a) -instance semigroupDisj :: (BooleanAlgebra a) => Semigroup (Disj a) -instance monoidDisj :: (BooleanAlgebra a) => Monoid (Disj a) -instance semiringDisj :: (BooleanAlgebra a) => Semiring (Disj a) -``` - -#### `runDisj` - -``` purescript -runDisj :: forall a. Disj a -> a -``` - - diff --git a/docs/Data/Monoid/Dual.md b/docs/Data/Monoid/Dual.md deleted file mode 100644 index 46c621f..0000000 --- a/docs/Data/Monoid/Dual.md +++ /dev/null @@ -1,40 +0,0 @@ -## Module Data.Monoid.Dual - -#### `Dual` - -``` purescript -newtype Dual a - = Dual a -``` - -The dual of a monoid. - -``` purescript -Dual x <> Dual y == Dual (y <> x) -mempty :: Dual _ == Dual mempty -``` - -##### Instances -``` purescript -instance eqDual :: (Eq a) => Eq (Dual a) -instance ordDual :: (Ord a) => Ord (Dual a) -instance functorDual :: Functor Dual -instance applyDual :: Apply Dual -instance applicativeDual :: Applicative Dual -instance bindDual :: Bind Dual -instance monadDual :: Monad Dual -instance extendDual :: Extend Dual -instance comonadDual :: Comonad Dual -instance invariantDual :: Invariant Dual -instance showDual :: (Show a) => Show (Dual a) -instance semigroupDual :: (Semigroup a) => Semigroup (Dual a) -instance monoidDual :: (Monoid a) => Monoid (Dual a) -``` - -#### `runDual` - -``` purescript -runDual :: forall a. Dual a -> a -``` - - diff --git a/docs/Data/Monoid/Endo.md b/docs/Data/Monoid/Endo.md deleted file mode 100644 index 959a12c..0000000 --- a/docs/Data/Monoid/Endo.md +++ /dev/null @@ -1,31 +0,0 @@ -## Module Data.Monoid.Endo - -#### `Endo` - -``` purescript -newtype Endo a - = Endo (a -> a) -``` - -Monoid of endomorphisms under composition. - -Composes of functions of type `a -> a`: -``` purescript -Endo f <> Endo g == Endo (f <<< g) -mempty :: Endo _ == Endo id -``` - -##### Instances -``` purescript -instance invariantEndo :: Invariant Endo -instance semigroupEndo :: Semigroup (Endo a) -instance monoidEndo :: Monoid (Endo a) -``` - -#### `runEndo` - -``` purescript -runEndo :: forall a. Endo a -> a -> a -``` - - diff --git a/docs/Data/Monoid/Multiplicative.md b/docs/Data/Monoid/Multiplicative.md deleted file mode 100644 index 85a361f..0000000 --- a/docs/Data/Monoid/Multiplicative.md +++ /dev/null @@ -1,40 +0,0 @@ -## Module Data.Monoid.Multiplicative - -#### `Multiplicative` - -``` purescript -newtype Multiplicative a - = Multiplicative a -``` - -Monoid and semigroup for semirings under multiplication. - -``` purescript -Multiplicative x <> Multiplicative y == Multiplicative (x * y) -mempty :: Multiplicative _ == Multiplicative one -``` - -##### Instances -``` purescript -instance eqMultiplicative :: (Eq a) => Eq (Multiplicative a) -instance ordMultiplicative :: (Ord a) => Ord (Multiplicative a) -instance functorMultiplicative :: Functor Multiplicative -instance applyMultiplicative :: Apply Multiplicative -instance applicativeMultiplicative :: Applicative Multiplicative -instance bindMultiplicative :: Bind Multiplicative -instance monadMultiplicative :: Monad Multiplicative -instance extendMultiplicative :: Extend Multiplicative -instance comonadMultiplicative :: Comonad Multiplicative -instance invariantMultiplicative :: Invariant Multiplicative -instance showMultiplicative :: (Show a) => Show (Multiplicative a) -instance semigroupMultiplicative :: (Semiring a) => Semigroup (Multiplicative a) -instance monoidMultiplicative :: (Semiring a) => Monoid (Multiplicative a) -``` - -#### `runMultiplicative` - -``` purescript -runMultiplicative :: forall a. Multiplicative a -> a -``` - - diff --git a/package.json b/package.json index 509a91f..aba57d3 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,11 @@ "private": true, "scripts": { "postinstall": "pulp dep install", - "build": "pulp build && rimraf docs && pulp docs" + "clean": "rimraf output && rimraf .pulp-cache", + "build": "pulp build" }, "devDependencies": { - "pulp": "^4.0.2", - "rimraf": "^2.4.1" + "pulp": "^8.0.0", + "rimraf": "^2.5.0" } } diff --git a/src/Data/Monoid.purs b/src/Data/Monoid.purs index 8688e17..1c9d36c 100644 --- a/src/Data/Monoid.purs +++ b/src/Data/Monoid.purs @@ -1,6 +1,11 @@ -module Data.Monoid where +module Data.Monoid + ( class Monoid, mempty + , module Data.Semigroup + ) where -import Prelude +import Data.Function (const) +import Data.Semigroup (class Semigroup, append, (<>)) +import Data.Unit (Unit, unit) -- | A `Monoid` is a `Semigroup` with a value `mempty`, which is both a -- | left and right unit for the associative operation `<>`: @@ -12,13 +17,13 @@ import Prelude -- | `Monoid`s are commonly used as the result of fold operations, where -- | `<>` is used to combine individual results, and `mempty` gives the result -- | of folding an empty collection of elements. -class (Semigroup m) <= Monoid m where +class Semigroup m <= Monoid m where mempty :: m instance monoidUnit :: Monoid Unit where mempty = unit -instance monoidFn :: (Monoid b) => Monoid (a -> b) where +instance monoidFn :: Monoid b => Monoid (a -> b) where mempty = const mempty instance monoidString :: Monoid String where diff --git a/src/Data/Monoid/Additive.purs b/src/Data/Monoid/Additive.purs index 4b06214..44a4440 100644 --- a/src/Data/Monoid/Additive.purs +++ b/src/Data/Monoid/Additive.purs @@ -1,12 +1,22 @@ module Data.Monoid.Additive where -import Prelude - -import Control.Comonad (Comonad) -import Control.Extend (Extend) - -import Data.Functor.Invariant (Invariant) -import Data.Monoid (Monoid) +import Control.Applicative (class Applicative) +import Control.Apply (class Apply) +import Control.Bind (class Bind) +import Control.Comonad (class Comonad) +import Control.Extend (class Extend) +import Control.Monad (class Monad) + +import Data.Bounded (class Bounded, top, bottom) +import Data.BoundedOrd (class BoundedOrd) +import Data.Eq (class Eq, (==)) +import Data.Functor (class Functor) +import Data.Functor.Invariant (class Invariant) +import Data.Monoid (class Monoid) +import Data.Ord (class Ord, compare) +import Data.Semigroup (class Semigroup, (<>)) +import Data.Semiring (class Semiring, (+), zero) +import Data.Show (class Show, show) -- | Monoid and semigroup for semirings under addition. -- | @@ -19,15 +29,24 @@ newtype Additive a = Additive a runAdditive :: forall a. Additive a -> a runAdditive (Additive x) = x -instance eqAdditive :: (Eq a) => Eq (Additive a) where +instance eqAdditive :: Eq a => Eq (Additive a) where eq (Additive x) (Additive y) = x == y -instance ordAdditive :: (Ord a) => Ord (Additive a) where +instance ordAdditive :: Ord a => Ord (Additive a) where compare (Additive x) (Additive y) = compare x y +instance boundedAdditive :: Bounded a => Bounded (Additive a) where + top = Additive top + bottom = Additive bottom + +instance boundedOrdAdditive :: BoundedOrd a => BoundedOrd (Additive a) + instance functorAdditive :: Functor Additive where map f (Additive x) = Additive (f x) +instance invariantAdditive :: Invariant Additive where + imap f _ (Additive x) = Additive (f x) + instance applyAdditive :: Apply Additive where apply (Additive f) (Additive x) = Additive (f x) @@ -45,14 +64,11 @@ instance extendAdditive :: Extend Additive where instance comonadAdditive :: Comonad Additive where extract = runAdditive -instance invariantAdditive :: Invariant Additive where - imap f _ (Additive x) = Additive (f x) - -instance showAdditive :: (Show a) => Show (Additive a) where - show (Additive a) = "Additive (" ++ show a ++ ")" +instance showAdditive :: Show a => Show (Additive a) where + show (Additive a) = "(Additive " <> show a <> ")" -instance semigroupAdditive :: (Semiring a) => Semigroup (Additive a) where +instance semigroupAdditive :: Semiring a => Semigroup (Additive a) where append (Additive a) (Additive b) = Additive (a + b) -instance monoidAdditive :: (Semiring a) => Monoid (Additive a) where +instance monoidAdditive :: Semiring a => Monoid (Additive a) where mempty = Additive zero diff --git a/src/Data/Monoid/Conj.purs b/src/Data/Monoid/Conj.purs index 5cf41f1..8453dda 100644 --- a/src/Data/Monoid/Conj.purs +++ b/src/Data/Monoid/Conj.purs @@ -1,11 +1,23 @@ module Data.Monoid.Conj where -import Prelude - -import Control.Comonad (Comonad) -import Control.Extend (Extend) - -import Data.Monoid (Monoid) +import Control.Applicative (class Applicative) +import Control.Apply (class Apply) +import Control.Bind (class Bind) +import Control.Comonad (class Comonad) +import Control.Extend (class Extend) +import Control.Monad (class Monad) + +import Data.BooleanAlgebra (class BooleanAlgebra, conj, disj) +import Data.Bounded (class Bounded, top, bottom) +import Data.BoundedOrd (class BoundedOrd) +import Data.Eq (class Eq, (==)) +import Data.Functor (class Functor) +import Data.Functor.Invariant (class Invariant) +import Data.Monoid (class Monoid) +import Data.Ord (class Ord, compare) +import Data.Semigroup (class Semigroup, (<>)) +import Data.Semiring (class Semiring) +import Data.Show (class Show, show) -- | Monoid under conjuntion. -- | @@ -18,19 +30,24 @@ newtype Conj a = Conj a runConj :: forall a. Conj a -> a runConj (Conj x) = x -instance eqConj :: (Eq a) => Eq (Conj a) where +instance eqConj :: Eq a => Eq (Conj a) where eq (Conj x) (Conj y) = x == y -instance ordConj :: (Ord a) => Ord (Conj a) where +instance ordConj :: Ord a => Ord (Conj a) where compare (Conj x) (Conj y) = compare x y -instance boundedConj :: (Bounded a) => Bounded (Conj a) where +instance boundedConj :: Bounded a => Bounded (Conj a) where top = Conj top bottom = Conj bottom +instance boundedOrdConj :: BoundedOrd a => BoundedOrd (Conj a) + instance functorConj :: Functor Conj where map f (Conj x) = Conj (f x) +instance invariantConj :: Invariant Conj where + imap f _ (Conj x) = Conj (f x) + instance applyConj :: Apply Conj where apply (Conj f) (Conj x) = Conj (f x) @@ -49,15 +66,15 @@ instance comonadConj :: Comonad Conj where extract = runConj instance showConj :: (Show a) => Show (Conj a) where - show (Conj a) = "Conj (" ++ show a ++ ")" + show (Conj a) = "(Conj " <> show a <> ")" -instance semigroupConj :: (BooleanAlgebra a) => Semigroup (Conj a) where +instance semigroupConj :: BooleanAlgebra a => Semigroup (Conj a) where append (Conj a) (Conj b) = Conj (conj a b) -instance monoidConj :: (BooleanAlgebra a) => Monoid (Conj a) where +instance monoidConj :: BooleanAlgebra a => Monoid (Conj a) where mempty = Conj top -instance semiringConj :: (BooleanAlgebra a) => Semiring (Conj a) where +instance semiringConj :: BooleanAlgebra a => Semiring (Conj a) where zero = Conj top one = Conj bottom add (Conj a) (Conj b) = Conj (conj a b) diff --git a/src/Data/Monoid/Disj.purs b/src/Data/Monoid/Disj.purs index 37d5f58..cdfe715 100644 --- a/src/Data/Monoid/Disj.purs +++ b/src/Data/Monoid/Disj.purs @@ -1,11 +1,22 @@ module Data.Monoid.Disj where -import Prelude - -import Control.Comonad (Comonad) -import Control.Extend (Extend) - -import Data.Monoid (Monoid) +import Control.Applicative (class Applicative) +import Control.Apply (class Apply) +import Control.Bind (class Bind) +import Control.Comonad (class Comonad) +import Control.Extend (class Extend) +import Control.Monad (class Monad) + +import Data.BooleanAlgebra (class BooleanAlgebra, conj, disj) +import Data.Bounded (class Bounded, top, bottom) +import Data.BoundedOrd (class BoundedOrd) +import Data.Eq (class Eq, (==)) +import Data.Functor (class Functor) +import Data.Monoid (class Monoid) +import Data.Ord (class Ord, compare) +import Data.Semigroup (class Semigroup, (<>)) +import Data.Semiring (class Semiring) +import Data.Show (class Show, show) -- | Monoid under disjuntion. -- | @@ -18,16 +29,18 @@ newtype Disj a = Disj a runDisj :: forall a. Disj a -> a runDisj (Disj x) = x -instance eqDisj :: (Eq a) => Eq (Disj a) where +instance eqDisj :: Eq a => Eq (Disj a) where eq (Disj x) (Disj y) = x == y -instance ordDisj :: (Ord a) => Ord (Disj a) where +instance ordDisj :: Ord a => Ord (Disj a) where compare (Disj x) (Disj y) = compare x y -instance boundedDisj :: (Bounded a) => Bounded (Disj a) where +instance boundedDisj :: Bounded a => Bounded (Disj a) where top = Disj top bottom = Disj bottom +instance boundedOrdDisj :: BoundedOrd a => BoundedOrd (Disj a) + instance functorDisj :: Functor Disj where map f (Disj x) = Disj (f x) @@ -48,16 +61,16 @@ instance extendDisj :: Extend Disj where instance comonadDisj :: Comonad Disj where extract = runDisj -instance showDisj :: (Show a) => Show (Disj a) where - show (Disj a) = "Disj (" ++ show a ++ ")" +instance showDisj :: Show a => Show (Disj a) where + show (Disj a) = "(Disj " <> show a <> ")" -instance semigroupDisj :: (BooleanAlgebra a) => Semigroup (Disj a) where +instance semigroupDisj :: BooleanAlgebra a => Semigroup (Disj a) where append (Disj a) (Disj b) = Disj (disj a b) -instance monoidDisj :: (BooleanAlgebra a) => Monoid (Disj a) where +instance monoidDisj :: BooleanAlgebra a => Monoid (Disj a) where mempty = Disj bottom -instance semiringDisj :: (BooleanAlgebra a) => Semiring (Disj a) where +instance semiringDisj :: BooleanAlgebra a => Semiring (Disj a) where zero = Disj bottom one = Disj top add (Disj a) (Disj b) = Disj (disj a b) diff --git a/src/Data/Monoid/Dual.purs b/src/Data/Monoid/Dual.purs index 5b82045..7e76ed7 100644 --- a/src/Data/Monoid/Dual.purs +++ b/src/Data/Monoid/Dual.purs @@ -1,12 +1,21 @@ module Data.Monoid.Dual where -import Prelude - -import Control.Comonad (Comonad) -import Control.Extend (Extend) - -import Data.Functor.Invariant (Invariant) -import Data.Monoid (Monoid, mempty) +import Control.Applicative (class Applicative) +import Control.Apply (class Apply) +import Control.Bind (class Bind) +import Control.Comonad (class Comonad) +import Control.Extend (class Extend) +import Control.Monad (class Monad) + +import Data.Bounded (class Bounded, top, bottom) +import Data.BoundedOrd (class BoundedOrd) +import Data.Eq (class Eq, (==)) +import Data.Functor (class Functor) +import Data.Functor.Invariant (class Invariant) +import Data.Monoid (class Monoid, mempty) +import Data.Ord (class Ord, compare) +import Data.Semigroup (class Semigroup, (<>)) +import Data.Show (class Show, show) -- | The dual of a monoid. -- | @@ -19,15 +28,24 @@ newtype Dual a = Dual a runDual :: forall a. Dual a -> a runDual (Dual x) = x -instance eqDual :: (Eq a) => Eq (Dual a) where +instance eqDual :: Eq a => Eq (Dual a) where eq (Dual x) (Dual y) = x == y -instance ordDual :: (Ord a) => Ord (Dual a) where +instance ordDual :: Ord a => Ord (Dual a) where compare (Dual x) (Dual y) = compare x y +instance boundedDual :: Bounded a => Bounded (Dual a) where + top = Dual top + bottom = Dual bottom + +instance boundedOrdDual :: BoundedOrd a => BoundedOrd (Dual a) + instance functorDual :: Functor Dual where map f (Dual x) = Dual (f x) +instance invariantDual :: Invariant Dual where + imap f _ (Dual x) = Dual (f x) + instance applyDual :: Apply Dual where apply (Dual f) (Dual x) = Dual (f x) @@ -45,14 +63,11 @@ instance extendDual :: Extend Dual where instance comonadDual :: Comonad Dual where extract = runDual -instance invariantDual :: Invariant Dual where - imap f _ (Dual x) = Dual (f x) - -instance showDual :: (Show a) => Show (Dual a) where - show (Dual a) = "Dual (" ++ show a ++ ")" +instance showDual :: Show a => Show (Dual a) where + show (Dual a) = "(Dual " <> show a <> ")" -instance semigroupDual :: (Semigroup a) => Semigroup (Dual a) where +instance semigroupDual :: Semigroup a => Semigroup (Dual a) where append (Dual x) (Dual y) = Dual (y <> x) -instance monoidDual :: (Monoid a) => Monoid (Dual a) where +instance monoidDual :: Monoid a => Monoid (Dual a) where mempty = Dual mempty diff --git a/src/Data/Monoid/Endo.purs b/src/Data/Monoid/Endo.purs index f376c77..bfe4cd3 100644 --- a/src/Data/Monoid/Endo.purs +++ b/src/Data/Monoid/Endo.purs @@ -1,9 +1,9 @@ module Data.Monoid.Endo where -import Prelude - -import Data.Functor.Invariant (Invariant) -import Data.Monoid (Monoid) +import Data.Function (id, (<<<)) +import Data.Functor.Invariant (class Invariant) +import Data.Monoid (class Monoid) +import Data.Semigroup (class Semigroup) -- | Monoid of endomorphisms under composition. -- | diff --git a/src/Data/Monoid/Multiplicative.purs b/src/Data/Monoid/Multiplicative.purs index 35cd759..58d3a42 100644 --- a/src/Data/Monoid/Multiplicative.purs +++ b/src/Data/Monoid/Multiplicative.purs @@ -1,12 +1,22 @@ module Data.Monoid.Multiplicative where -import Prelude - -import Control.Comonad (Comonad) -import Control.Extend (Extend) - -import Data.Functor.Invariant (Invariant) -import Data.Monoid (Monoid) +import Control.Applicative (class Applicative) +import Control.Apply (class Apply) +import Control.Bind (class Bind) +import Control.Comonad (class Comonad) +import Control.Extend (class Extend) +import Control.Monad (class Monad) + +import Data.Bounded (class Bounded, top, bottom) +import Data.BoundedOrd (class BoundedOrd) +import Data.Eq (class Eq, (==)) +import Data.Functor (class Functor) +import Data.Functor.Invariant (class Invariant) +import Data.Monoid (class Monoid) +import Data.Ord (class Ord, compare) +import Data.Semigroup (class Semigroup, (<>)) +import Data.Semiring (class Semiring, (*), one) +import Data.Show (class Show, show) -- | Monoid and semigroup for semirings under multiplication. -- | @@ -25,9 +35,18 @@ instance eqMultiplicative :: (Eq a) => Eq (Multiplicative a) where instance ordMultiplicative :: (Ord a) => Ord (Multiplicative a) where compare (Multiplicative x) (Multiplicative y) = compare x y +instance boundedMultiplicative :: Bounded a => Bounded (Multiplicative a) where + top = Multiplicative top + bottom = Multiplicative bottom + +instance boundedOrdMultiplicative :: BoundedOrd a => BoundedOrd (Multiplicative a) + instance functorMultiplicative :: Functor Multiplicative where map f (Multiplicative x) = Multiplicative (f x) +instance invariantMultiplicative :: Invariant Multiplicative where + imap f _ (Multiplicative x) = Multiplicative (f x) + instance applyMultiplicative :: Apply Multiplicative where apply (Multiplicative f) (Multiplicative x) = Multiplicative (f x) @@ -45,11 +64,8 @@ instance extendMultiplicative :: Extend Multiplicative where instance comonadMultiplicative :: Comonad Multiplicative where extract = runMultiplicative -instance invariantMultiplicative :: Invariant Multiplicative where - imap f _ (Multiplicative x) = Multiplicative (f x) - instance showMultiplicative :: (Show a) => Show (Multiplicative a) where - show (Multiplicative a) = "Multiplicative (" ++ show a ++ ")" + show (Multiplicative a) = "(Multiplicative " <> show a <> ")" instance semigroupMultiplicative :: (Semiring a) => Semigroup (Multiplicative a) where append (Multiplicative a) (Multiplicative b) = Multiplicative (a * b)