groups (empty) → 0.1
raw patch · 4 files changed
+87/−0 lines, 4 filesdep +basesetup-changed
Dependencies added: base
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- groups.cabal +19/−0
- src/Data/Group.hs +36/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Nathan "Taneb" van Doorn++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 Nathan "Taneb" van Doorn 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
+ groups.cabal view
@@ -0,0 +1,19 @@+name: groups+version: 0.1+synopsis: Haskell 98 groups+description: + Haskell 98 groups. A group is a monoid with invertibility.+license: BSD3+license-file: LICENSE+author: Nathan "Taneb" van Doorn+maintainer: nvd1234@gmail.com+copyright: Copyright (C) 2013 Nathan van Doorn+category: Algebra, Data, Math+build-type: Simple+cabal-version: >=1.8++library+ exposed-modules: Data.Group+ -- other-modules: + build-depends: base ==4.5.*+ hs-source-dirs: src
+ src/Data/Group.hs view
@@ -0,0 +1,36 @@+module Data.Group where++import Data.Monoid++-- |A 'Group' is a 'Monoid' plus a function, 'invert', such that: +--+-- @a <> invert a == mempty@+class Monoid m => Group m where+ invert :: m -> m+ +instance Group () where+ invert () = ()++instance Num a => Group (Sum a) where+ invert = Sum . negate . getSum+ {-# INLINE invert #-}+ +instance Fractional a => Group (Product a) where+ invert = Product . recip . getProduct+ {-# INLINE invert #-}++instance Group a => Group (Dual a) where+ invert = Dual . invert . getDual+ {-# INLINE invert #-}+ +instance (Group a, Group b) => Group (a, b) where+ invert (a, b) = (invert a, invert b)+ +instance (Group a, Group b, Group c) => Group (a, b, c) where+ invert (a, b, c) = (invert a, invert b, invert c)++instance (Group a, Group b, Group c, Group d) => Group (a, b, c, d) where+ invert (a, b, c, d) = (invert a, invert b, invert c, invert d)++instance (Group a, Group b, Group c, Group d, Group e) => Group (a, b, c, d, e) where+ invert (a, b, c, d, e) = (invert a, invert b, invert c, invert d, invert e)