Skip to content

Commit

Permalink
ReaderWriterIO: instance Semigroup enables compatibility with GHC-8.4…
Browse files Browse the repository at this point in the history
….1 (#168)

* ReaderWriterIO: instance Semigroup
enables compatibility with GHC-8.4.1

* Cabal: allow pqueue-1.4

* Prim.Types: Semigroup instances

* Prim.Types: explicit import of Monoid
compatibility with GHC-7.6.3

* Cabal.Test-Suite.Build-Depends: add semigroups package
  • Loading branch information
thielema authored and ocharles committed Mar 22, 2018
1 parent d42fb55 commit d911162
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
5 changes: 3 additions & 2 deletions reactive-banana/reactive-banana.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Library
vault == 0.3.*,
unordered-containers >= 0.2.1.0 && < 0.3,
hashable >= 1.1 && < 1.3,
pqueue >= 1.0 && < 1.4
pqueue >= 1.0 && < 1.5

exposed-modules:
Control.Event.Handler,
Expand Down Expand Up @@ -85,5 +85,6 @@ Test-Suite tests
HUnit >= 1.2 && < 2,
test-framework >= 0.6 && < 0.9,
test-framework-hunit >= 0.2 && < 0.4,
reactive-banana, vault, containers, transformers,
reactive-banana, vault, containers,
semigroups, transformers,
unordered-containers, hashable, psqueues, pqueue
4 changes: 4 additions & 0 deletions reactive-banana/src/Control/Monad/Trans/ReaderWriterIO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Data.IORef
import Data.Monoid
import Data.Semigroup

{-----------------------------------------------------------------------------
Type and class instances
Expand All @@ -35,6 +36,9 @@ instance MonadFix m => MonadFix (ReaderWriterIOT r w m) where mfix = mfixR
instance MonadIO m => MonadIO (ReaderWriterIOT r w m) where liftIO = liftIOR
instance MonadTrans (ReaderWriterIOT r w) where lift = liftR

instance (Monad m, a ~ ()) => Semigroup (ReaderWriterIOT r w m a) where
mx <> my = mx >> my

instance (Monad m, a ~ ()) => Monoid (ReaderWriterIOT r w m a) where
mempty = return ()
mx `mappend` my = mx >> my
Expand Down
21 changes: 15 additions & 6 deletions reactive-banana/src/Reactive/Banana/Prim/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import Control.Monad.Trans.Reader
import Control.Monad.Trans.ReaderWriterIO
import Data.Functor
import Data.Hashable
import Data.Monoid
import Data.Monoid (Monoid, mempty, mappend)
import Data.Semigroup
import qualified Data.Vault.Lazy as Lazy
import System.IO.Unsafe
import System.Mem.Weak
Expand Down Expand Up @@ -51,9 +52,12 @@ newtype BuildW = BuildW (DependencyBuilder, [Output], Action, Maybe (Build ()))
-- , late build actions
-- )

instance Semigroup BuildW where
BuildW x <> BuildW y = BuildW (x <> y)

instance Monoid BuildW where
mempty = BuildW mempty
(BuildW x) `mappend` (BuildW y) = BuildW (x `mappend` y)
mempty = BuildW mempty
mappend = (<>)

type BuildIO = Build

Expand All @@ -70,9 +74,11 @@ ground = 0

-- | 'IO' actions as a monoid with respect to sequencing.
newtype Action = Action { doit :: IO () }
instance Semigroup Action where
Action x <> Action y = Action (x >> y)
instance Monoid Action where
mempty = Action $ return ()
(Action x) `mappend` (Action y) = Action (x >> y)
mappend = (<>)

-- | Lens-like functionality.
data Lens s a = Lens (s -> a) (a -> s -> s)
Expand Down Expand Up @@ -185,9 +191,12 @@ beginning = T 0
next :: Time -> Time
next (T n) = T (n+1)

instance Semigroup Time where
T x <> T y = T (max x y)

instance Monoid Time where
mappend (T x) (T y) = T (max x y)
mempty = beginning
mappend = (<>)
mempty = beginning

{-----------------------------------------------------------------------------
Notes
Expand Down

0 comments on commit d911162

Please sign in to comment.