packages feed

semigroups (empty) → 0.1.0

raw patch · 4 files changed

+157/−0 lines, 4 filesdep +basedep +containerssetup-changed

Dependencies added: base, containers

Files

+ Data/Semigroup.hs view
@@ -0,0 +1,96 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Data.Semigroup+-- Copyright   :  (C) 2011 Edward Kmett,+-- License     :  BSD-style (see the file LICENSE)+--+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  portable+--+----------------------------------------------------------------------------+module Data.Semigroup ( +    Semigroup(..)+  , Min(..)+  , Max(..)+  , Option(..)+  , WrappedMonoid(..)+  ) where++import Prelude hiding (foldr1)+import Data.Monoid+import Data.Foldable++infixl 4 <> ++class Semigroup a where+  (<>) :: a -> a -> a++  fold1 :: Foldable f => f a -> a+  fold1 = foldr1 (<>) ++-- Semigroups from Data.Monoid++instance Semigroup a => Semigroup (Dual a) where+  Dual a <> Dual b = Dual (b <> a)++instance Semigroup (Endo a) where+  Endo f <> Endo g = Endo (f . g) ++instance Semigroup All where+  All a <> All b = All (a && b)++instance Semigroup Any where+  Any a <> Any b = Any (a || b)++instance Num a => Semigroup (Sum a) where+  Sum a <> Sum b = Sum (a + b)++instance Num a => Semigroup (Product a) where+  Product a <> Product b = Product (a * b)++instance Semigroup (First a) where+  First Nothing <> b = b+  a             <> _ = a++instance Semigroup (Last a) where+  a <> Last Nothing = a+  _ <> b            = b+++newtype Min a = Min { getMin :: a } +instance Ord a => Semigroup (Min a) where+  Min a <> Min b = Min (a `min` b)++newtype Max a = Max { getMax :: a } +instance Ord a => Semigroup (Max a) where+  Max a <> Max b = Max (a `min` b)++-- (==)/XNOR on Bool forms a Semigroup, but has no good name+++newtype WrappedMonoid m = WrapMonoid { unwrapMonoid :: m } +  deriving (Show, Read, Eq, Ord)++instance Monoid m => Semigroup (WrappedMonoid m) where+  WrapMonoid a <> WrapMonoid b = WrapMonoid (a `mappend` b)++instance Monoid m => Monoid (WrappedMonoid m) where+  mempty = WrapMonoid mempty+  WrapMonoid a `mappend` WrapMonoid b = WrapMonoid (a `mappend` b)+++newtype Option a = Option { runOption :: Maybe a } +  deriving (Show, Read, Eq, Ord)++instance Semigroup a => Semigroup (Option a) where+  Option Nothing <> b = b+  a <> Option Nothing = a+  Option (Just a) <> Option (Just b) = Option (Just (a <> b))++instance Semigroup a => Monoid (Option a) where+  mempty = Option Nothing++  Option Nothing `mappend` b = b+  a `mappend` Option Nothing = a+  Option (Just a) `mappend` Option (Just b) = Option (Just (a <> b))
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright 2011 Edward Kmett++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:++1. Redistributions of source code must retain the above copyright+   notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright+   notice, this list of conditions and the following disclaimer in the+   documentation and/or other materials provided with the distribution.++3. Neither the name of the author nor the names of his contributors+   may be used to endorse or promote products derived from this software+   without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+POSSIBILITY OF SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,7 @@+#!/usr/bin/runhaskell+> module Main (main) where++> import Distribution.Simple++> main :: IO ()+> main = defaultMain
+ semigroups.cabal view
@@ -0,0 +1,24 @@+name:          semigroups+category:      Control, Comonads+version:       0.1.0+license:       BSD3+cabal-version: >= 1.2+license-file:  LICENSE+author:        Edward A. Kmett+maintainer:    Edward A. Kmett <ekmett@gmail.com>+stability:     provisional+homepage:      http://comonad.com/reader/+copyright:     Copyright (C) 2008-2011 Edward A. Kmett, Copyright (C) 2004-2008 Dave Menendez+synopsis:      Haskell 98 semigroups+description:   Haskell 98 semigroups+build-type:    Simple++library+  build-depends: +    base >= 4 && < 4.4,+    containers >= 0.4 && < 0.5++  exposed-modules:+    Data.Semigroup++  ghc-options: -Wall