packages feed

monus 0.1.0.0 → 0.2.0.0

raw patch · 4 files changed

+46/−7 lines, 4 filesdep ~basedep ~containersPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base, containers

API changes (from Hackage documentation)

Files

README.md view
@@ -1,1 +1,15 @@-# subtraction-semigroups+monus+=====++A 'Monus' is a commutative monoid that allows a notion of substraction, with the following laws:++* x <> (y - x) = y <> (x - y)+* (x - y) - z = x - (y <> z)+* x - x = mempty+* mempty - x = mempty++You can read more about them here: https://en.wikipedia.org/wiki/Monus++## Installation++Install with `cabal-install`
monus.cabal view
@@ -1,7 +1,18 @@ cabal-version:  2.2 name:           monus-version:        0.1.0.0-description:    Please see the README on GitHub at <https://github.com/andrewthad/monus#readme>+version:        0.2.0.0+synopsis:       a 'Monus' is a commutative monoid that allows a notion of substraction.+category:       Data+description:    A 'Monus' is a commutative monoid that allows a notion of substraction,+                with the following laws:+                .+                x <> (y - x) = y <> (x - y)+                .+                (x - y) - z = x - (y <> z)+                .+                x - x = mempty+                .+                mempty - x = mempty homepage:       https://github.com/andrewthad/monus#readme bug-reports:    https://github.com/andrewthad/monus/issues author:         Andrew Martin@@ -25,8 +36,8 @@     Data.Map.Annihilate   hs-source-dirs: src   build-depends:-    , base >=4.5 && <5-    , containers >= 0.4.2.1+    , base >=4.9 && < 4.13+    , containers >= 0.5.7.1 && < 0.7.0.0   default-language: Haskell2010  test-suite test
src/Data/Map/Annihilate.hs view
@@ -23,15 +23,21 @@ import qualified Data.Map.Strict as M import qualified Data.Map.Merge.Strict as MM --- todo: manually write Show instance+-- | A 'Map' that supports annihilation, i.e. it is a 'Monus',+--   where for 'Monus' values, matching keys will be subtracted,+--   and keys not shared by both 'Map's will be discarded. newtype Map k v = Map (M.Map k v)   deriving (Eq,Ord,Functor,Foldable,Show)+--todo: manually write Show instance +-- | Create a singleton 'Map'. singleton :: (Monoid v, Eq v) => k -> v -> Map k v singleton k v = if v == mempty   then Map M.empty   else Map (M.singleton k v) +-- | Lookup a value in a 'Map'. If no value is found, this+--   returns 'mempty'. lookup :: (Ord k, Monoid v) => k -> Map k v -> v lookup k (Map m) = fromMaybe mempty (M.lookup k m) 
src/Data/Monoid/Monus/Generic.hs view
@@ -4,6 +4,8 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE TypeOperators #-} +-- | This module provides generic deriving tools for monuses for+--   product-like structures. module Data.Monoid.Monus.Generic   ( GMonus(..)   , gmonus@@ -15,13 +17,19 @@ import Data.Monoid.Monus import Prelude hiding (Num(..)) --- | Useful with -XDerivingVia.+-- | This type is useful with -XDerivingVia. newtype WrappedMonus a = WrappedMonus a   deriving (Generic, Semigroup, Monoid)  instance Monus a => Monus (WrappedMonus a) where   monus = gmonus; +-- | Generically generate a 'Monus' 'monus' operation for any type+--   implementing 'Generic'. It is only defined for product types.+--+-- @+-- 'gmonus' a b = 'gmonus' b a+-- @ gmonus :: (Generic a, GMonus (Rep a)) => a -> a -> a gmonus x y = to (from x `gmonus'` from y)