Commits

Tony Morris  committed ed66d0e

added Min and Max

  • Participants
  • Parent commits 9ebbd0e

Comments (0)

Files changed (3)

+:m + Test.QuickCheck
+:l Data.Semigroup
+:m + Test.QuickCheck Data.Semigroup 
+

File Data/Semigroup.hs

 -- | A semigroup is a binary associative operation.
-module Data.Semigroup(
-                     Semigroup((.++.)),
-                     (<++>)
-                     ) where
+module Data.Semigroup (
+  Semigroup((.++.))
+, (<++>)
+, Max(..)
+, Min(..)
+, BoundedMax(..)
+, BoundedMin(..)
+) where
 
 import Data.Monoid
 import Data.Sequence
 instance Semigroup B.ByteString where
   (.++.) = mappend
 
+newtype Max a = Max {
+  runMax :: a
+} deriving (Eq, Ord, Show, Read)
+
+instance Ord a => Semigroup (Max a) where
+  Max a .++. Max b = Max (a `max` b)
+
+newtype Min a = Min {
+  runMin :: a
+} deriving (Eq, Ord, Show, Read)
+
+instance Ord a => Semigroup (Min a) where
+  Min a .++. Min b = Min (a `min` b)
+
+newtype BoundedMax a = BoundedMax {
+  runBoundedMax :: Maybe a
+} deriving (Eq, Ord, Show, Read)
+
+instance Ord a => Monoid (BoundedMax a) where
+  mempty = BoundedMax Nothing
+  mappend = max
+
+newtype BoundedMin a = BoundedMin {
+  runBoundedMin :: Maybe a
+} deriving (Eq, Ord, Show, Read)
+
+instance Ord a => Monoid (BoundedMin a) where
+  mempty = BoundedMin Nothing
+  mappend = min
+

File Semigroup.cabal

 Name:                Semigroup
-Version:             0.0.6
+Version:             0.0.7
 License:             BSD3
 License-File:        LICENSE
 Synopsis:            A semigroup
 Description:         A semigroup is a binary associative operation
-Homepage:            http://code.google.com/p/semigroup/
+Homepage:            https://bitbucket.org/dibblego/semigroup/
 Category:            Data
 Author:              Tony Morris
-Maintainer:          code@tmorris.net
-Copyright:           2010 Tony Morris
+Maintainer:          ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ
+Copyright:           2010-2011 Tony Morris
 build-type:          Simple
 cabal-version:       >= 1.2