packages feed

annihilator (empty) → 0.1.0.0

raw patch · 4 files changed

+140/−0 lines, 4 filesdep +basesetup-changed

Dependencies added: base

Files

+ Control/Annihilator.hs view
@@ -0,0 +1,78 @@++-- | A class for Annihilators, which define a binary function '>|>' that follows+-- the mathematical properties of: absorbing element, associativity, and+-- commutativity.+module Control.Annihilator+    ( Annihilator(..)+    , (<|<)+    , aconcat+    , amappend+    , amconcat+    , avoid+    )+    where++-- | Annihilators are semigroups with annihilators, i.e. the+-- following laws should hold:+--+-- prop> ann >|> b = ann+-- prop> a >|> ann = ann+-- prop> a >|> b = b+class Annihilator a where+    -- | Annihilating element of '>|>'.+    ann :: a++    -- | Annihilating operator, returns the rightmost element if no+    -- annihilators 'ann' are present.+    (>|>) :: a -> a -> a+++instance Annihilator () where+    ann = ()++    _ >|> _ = ()++instance Annihilator (Maybe a) where+    ann = Nothing++    Nothing >|> _ = Nothing+    _ >|> Nothing = Nothing+    _ >|> a = a++instance Annihilator ([] a) where+    ann = []++    [] >|> _ = []+    _ >|> [] = []+    _ >|> a = a++instance (Annihilator a, Annihilator b) => Annihilator (a, b) where+    ann = (ann, ann)++    (a1, b1) >|> (a2, b2) = (a1 >|> a2, b1 >|> b2)+++-- | Flipped version of '>|>'.+(<|<) :: Annihilator a => a -> a -> a+(<|<) = flip (>|>)++-- | Annihilating concatenation.+aconcat :: (Annihilator a, Foldable t) => t a -> a+aconcat as+    | null as   = ann+    | otherwise = foldr1 (>|>) as++-- | Monadic append with the annihilating operator guarding each argument.+amappend :: (Annihilator a, Monoid a) => a -> a -> a+amappend a b = (a >|> b) `mappend` (a <|< b)++-- | Monadic concatenation with the annihilating operator guarding each argument.+amconcat :: (Annihilator a, Monoid a, Foldable t) => t a -> a+amconcat as+    | null as   = ann+    | otherwise = foldr1 amappend as++-- | Discard the argument and return 'ann'.+avoid :: Annihilator a => a -> a+avoid = const ann+
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Benedict Aas (c) 2016++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * 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.++    * Neither the name of Author name here nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"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 COPYRIGHT+OWNER 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.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ annihilator.cabal view
@@ -0,0 +1,30 @@+name:                annihilator+version:             0.1.0.0+synopsis:            Semigroups with annihilators and utility functions+description:+    Annihilators are semigroups with annihilators and therefore almost act as+    the opposite of Alternative. This package comes with the typeclass and+    utility functions.+homepage:            http://github.com/Shou/annihilator#readme+bug-reports:         http://github.com/Shou/annihilator/issues+license:             BSD3+license-file:        LICENSE+author:              Benedict Aas+maintainer:          x@shou.io+copyright:           2016 Benedict Aas+category:            Control +build-type:          Simple+-- extra-source-files:+cabal-version:       >=1.10+tested-with:+    GHC==7.10.3++library+  exposed-modules:     Control.Annihilator+  build-depends:       base >= 4.7 && < 5+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/Shou/annihilator+