From 1a942633838f7ba9b6132dadd5abd2d2ff1e574f Mon Sep 17 00:00:00 2001 From: Tom Harding Date: Wed, 18 Apr 2018 09:06:56 +0100 Subject: [PATCH] Add Monoid instance for Effect Exactly the same as it was for Eff: Effect now has the regular applicative monoid instance that we all know and love. --- bower.json | 3 ++- src/Effect.purs | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index b07b03d..aefc25b 100644 --- a/bower.json +++ b/bower.json @@ -17,6 +17,7 @@ "package.json" ], "dependencies": { - "purescript-prelude": "^3.0.0" + "purescript-prelude": "^3.0.0", + "purescript-monoid": "^3.3.0" } } diff --git a/src/Effect.purs b/src/Effect.purs index 36af221..af60bcd 100644 --- a/src/Effect.purs +++ b/src/Effect.purs @@ -4,11 +4,13 @@ module Effect ) where import Control.Applicative (class Applicative, liftA1) -import Control.Apply (class Apply) +import Control.Apply (class Apply, lift2) import Control.Bind (class Bind) import Control.Monad (class Monad, ap) import Data.Functor (class Functor) +import Data.Monoid (class Monoid, mempty) +import Data.Semigroup (class Semigroup, append) import Data.Unit (Unit) -- | The `Effect` type constructor is used to represent _native_ effects. @@ -28,6 +30,12 @@ instance applyEffect :: Apply Effect where instance applicativeEffect :: Applicative Effect where pure = pureE +instance semigroupEffect :: Semigroup a => Semigroup (Effect a) where + append = lift2 append + +instance monoidEffect :: Monoid a => Monoid (Effect a) where + mempty = pureE mempty + foreign import pureE :: forall a. a -> Effect a instance bindEffect :: Bind Effect where