Commits

Tony Morris  committed d8c806f

Use MTL Identity instead of our own

  • Participants
  • Parent commits aef1b7d

Comments (0)

Files changed (2)

File Data/Semigroup.hs

 -- | A semigroup is a binary associative operation.
 module Data.Semigroup(
                      Semigroup((.++.)),
-                     Identity,
                      (<++>)
                      ) where
 
 import Data.Monoid
+import Control.Monad.Identity
 import Control.Applicative
 
 -- | A binary operation that must satisfy associativity. Unlike a @Monoid@, an identity in not essential.
 class Semigroup a where
   (.++.) :: a -> a -> a
 
--- | A wrapper used to construct a @Semigroup@ from a @Monoid@.
-newtype Identity a = Identity { run :: a }
-
 -- | A binary associative operation lifted into an applicative functor.
 (<++>) :: (Applicative f, Semigroup a) => f a -> f a -> f a
 (<++>) = liftA2 (.++.)
 
-instance Functor Identity where
-  fmap f (Identity a) = Identity (f a)
-
-instance Applicative Identity where
-  pure = Identity
-  Identity f <*> Identity a = Identity (f a)
-
-instance Monad Identity where
-  return = Identity
-  Identity a >>= f = f a
-
 instance Monoid a => Semigroup (Identity a) where
-  (.++.) = liftA2 mappend
+  (.++.) = liftM2 mappend
 
 instance Semigroup () where
   _ .++. _ = ()
   (a1, b1, c1, d1, e1) .++. (a2, b2, c2, d2, e2) = (a1 .++. a2, b1 .++. b2, c1 .++. c2, d1 .++. d2, e1 .++. e2)
 
 instance Semigroup Ordering where
-  a .++. b = run (Identity a .++. Identity b)
+  a .++. b = runIdentity (Identity a .++. Identity b)
 
 instance Semigroup All where
-  a .++. b = run (Identity a .++. Identity b)
+  a .++. b = runIdentity (Identity a .++. Identity b)
 
 instance Semigroup Any where
-  a .++. b = run (Identity a .++. Identity b)
+  a .++. b = runIdentity (Identity a .++. Identity b)
 
 instance Semigroup a => Semigroup (Dual a) where
   Dual a .++. Dual b = Dual (b .++. a)
 
 instance Semigroup (Endo a) where
-  a .++. b = run (Identity a .++. Identity b)
+  a .++. b = runIdentity (Identity a .++. Identity b)
 
 instance Num a => Semigroup (Product a) where
-  a .++. b = run (Identity a .++. Identity b)
+  a .++. b = runIdentity (Identity a .++. Identity b)
 
 instance Num a => Semigroup (Sum a) where
-  a .++. b = run (Identity a .++. Identity b)
+  a .++. b = runIdentity (Identity a .++. Identity b)
 
 instance Semigroup a => Semigroup (Maybe a) where
   Nothing .++. b = b
   Just a .++. Just b = Just (a .++. b)
 
 instance Semigroup (First a) where
-  a .++. b = run (Identity a .++. Identity b)
+  a .++. b = runIdentity (Identity a .++. Identity b)
 
 instance Semigroup (Last a) where
-  a .++. b = run (Identity a .++. Identity b)
+  a .++. b = runIdentity (Identity a .++. Identity b)
 
 instance Semigroup [a] where
   (.++.) = (++)

File Semigroup.cabal

 Name:                Semigroup
-Version:             0.0.3
+Version:             0.0.5
 License:             BSD3
 License-File:        LICENSE
 Synopsis:            A semigroup
 cabal-version:       >= 1.2
 
 Flag small_base
-  Description:     Choose the new, split-up base package.
+  Description:       Choose the new, split-up base package.
 
 Library
-  if flag(small_base)
-    Build-Depends: base < 5 && >= 3
-  else
-    Build-Depends: base < 5 && >= 3
+  Build-Depends:     base >= 4, mtl
 
-  GHC-Options:    -Wall
-  Exposed-Modules: Data.Semigroup
+  GHC-Options:       -Wall
+  Exposed-Modules:   Data.Semigroup