semiring-simple 0.2.1.0 → 1.0.0.0
raw patch · 3 files changed
+145/−72 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.Semiring: (.+., .*.) :: Semiring s => s -> s -> s
- Data.Semiring: instance Num a => Semiring a
- Data.Semiring: instance Semiring Bool
- Data.Semiring: instance Semiring a => Monoid a
- Data.Semiring: zero, one :: Semiring s => s
+ Data.Semiring: (<+>) :: Monoid m => m -> m -> m
+ Data.Semiring: (<.>) :: Semiring m => m -> m -> m
+ Data.Semiring: infixl 5 <+>
+ Data.Semiring: one :: Semiring m => m
+ Data.Semiring: zero :: Monoid m => m
- Data.Semiring: class Semiring s
+ Data.Semiring: class Monoid m => Semiring m
Files
- semiring-simple.cabal +12/−24
- src/Data/Semiring.hs +67/−48
- stack.yaml +66/−0
semiring-simple.cabal view
@@ -1,8 +1,5 @@--- Initial semiring.cabal generated by cabal init. For further --- documentation, see http://haskell.org/cabal/users-guide/- name: semiring-simple-version: 0.2.1.0+version: 1.0.0.0 synopsis: A module for dealing with semirings. description: Semirings are like normal rings, except you can't subtract. This library@@ -10,33 +7,24 @@ license: BSD3 license-file: LICENSE author: Thomas Wilke, Frank Huch, Sebastian Fischer, Peter Harpending-maintainer: Peter Harpending <pharpend2@gmail.com>-copyright: 2014, Peter Harpending.+maintainer: Peter Harpending <peter@harpending.org>+copyright: 2014-2016, Peter Harpending. category: Math build-type: Simple-extra-source-files: README.md cabal-version: >=1.10+extra-source-files:+ README.md+ LICENSE+ stack.yaml library+ default-language: Haskell2010+ hs-source-dirs: src/ exposed-modules:- Data.Semiring- - -- Modules included in this library but not exported.- -- other-modules: - - -- LANGUAGE extensions used by modules in this package.- -- other-extensions: - - -- Other library packages from which modules are imported.+ Data.Semiring build-depends:- base >=4 && <5- - -- Directories containing source files.- hs-source-dirs: src/- - -- Base language which the package is written in.- default-language: Haskell2010+ base >=4 && <5 source-repository head type: git- location: https://github.com/pharpend/semiring.git+ location: https://gitlab.com:pharpend/semiring-simple.git
src/Data/Semiring.hs view
@@ -1,62 +1,81 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE UndecidableInstances #-}--{- |-Module : Data.Semiring.Tropical.Skel-Description : A module for Tropical whatever-Copyright : 2012, Thomas Wilke, Frank Huch, Sebastian Fischer- 2014, Peter Harpending-License : BSD3-Maintainer : Peter Harpending <pharpend2@gmail.com>-Stability : experimental-Portability : archlinux--This library provides a type class for semirings.---}--module Data.Semiring where--import Data.Monoid- -- |+-- Module : Data.Semiring+-- Description : Semirings+-- Copyright : 2012, Thomas Wilke, Frank Huch, Sebastian Fischer+-- 2014-2016, Peter Harpending+-- License : BSD3+-- Maintainer : Peter Harpending <peter@harpending.org>+-- Stability : experimental+-- Portability : portable+-- +-- This library provides a type class for semirings.+-- -- A semiring is an additive commutative monoid with identity 'zero': -- --- > a .+. b == b .+. a--- > zero .+. a == a--- > (a .+. b) .+. c == a .+. (b .+. c)+-- Most Haskellers are familiar with the 'Monoid' typeclass: -- --- A semiring is a multiplicative monoid with identity 'one':+-- > zero <+> a ≡ a+-- > (a <+> b) <+> c ≡ a <+> (b <+> c) -- --- > one .*. a == a--- > a .*. one == a--- > (a .*. b) .*. c == a .*. (b .*. c)+-- In this case, we've aliased -- +-- > zero = mempty+-- > (<+>) = mappend+-- +-- A commutative monoid adds the requirement of symmetry:+-- +-- > a <+> b ≡ b <+> a+-- +-- A semiring adds the requirement of a multiplication-like operator. However,+-- it does not require the existence of multiplicative inverses,+-- i.e. division. Moreover, multiplication does not need to be commutative.+-- +-- > one <.> a ≡ a+-- > a <.> one ≡ a+-- > (a <.> b) <.> c ≡ a <.> (b <.> c)+-- -- Multiplication distributes over addition: -- --- > a .*. (b .+. c) == (a .*. b) .+. (a .*. c)--- > (a .+. b) .*. c == (a .*. c) .+. (b .*. c)+-- > a <.> (b <+> c) ≡ (a <.> b) <+> (a <.> b)+-- > (a <+> b) <>. c ≡ (a <.> c) <+> (b <.> c) -- -- 'zero' annihilates a semiring with respect to multiplication: -- --- > zero .*. a == zero--- > a .*. zero == zero-class Semiring s where- zero, one :: s- (.+.), (.*.) :: s -> s -> s+-- > zero <.> a ≡ zero+-- > a <.> zero ≡ zero+-- +-- The classic example of a semiring is the "Tropical numbers". The Tropical+-- numbers, or T, are just real numbers with different operators.+-- +-- > zero = ∞+-- > a <+> b = minimum {a, b}+-- > one = 0+-- > a <.> b = a + b+-- +-- We can easily verify that these satisfy the semiring axioms:+-- +-- > minimum {∞, a} = minimum {a, ∞} = a, for all a+-- > minimum {a, b} = minimum {b, a}, for all a, b+-- > minimum {a, minimum{b, c}} = minimum {minimum {a, b}, c}, for all a, b, c+-- +-- > 0 + a = a + 0 = a, for all a+-- > a + (b + c) = (a + b) + c, for all a, b, c+-- > a + minimum {b, c} = minimum {a, b} + minimum{a, c}, for all a, b, c+-- > minimum {a, b} + c = minimum {a, c} + minimum{b, c}, for all a, b, c+-- > a + ∞ = ∞ + a = ∞, for all a+module Data.Semiring where -instance Semiring a => Monoid a where- mempty = zero- mappend = (.+.)+import Data.Monoid -instance Num a => Semiring a where- zero = 0- one = 1- (.+.) = (+)- (.*.) = (*)+-- |Alias for 'mappend'.+infixl 5 <+>+(<+>) :: Monoid m => m -> m -> m+(<+>) = mappend -instance Semiring Bool where- zero = False- one = True- (.+.) = (||)- (.*.) = (&&)+-- |Alias for 'mempty'+zero :: Monoid m => m+zero = mempty++class Monoid m => Semiring m where+ one :: m+ (<.>) :: m -> m -> m
+ stack.yaml view
@@ -0,0 +1,66 @@+# This file was automatically generated by 'stack init'+# +# Some commonly used options have been documented as comments in this file.+# For advanced use and comprehensive documentation of the format, please see:+# http://docs.haskellstack.org/en/stable/yaml_configuration/++# Resolver to choose a 'specific' stackage snapshot or a compiler version.+# A snapshot resolver dictates the compiler version and the set of packages+# to be used for project dependencies. For example:+# +# resolver: lts-3.5+# resolver: nightly-2015-09-21+# resolver: ghc-7.10.2+# resolver: ghcjs-0.1.0_ghc-7.10.2+# resolver:+# name: custom-snapshot+# location: "./custom-snapshot.yaml"+resolver: lts-5.8++# User packages to be built.+# Various formats can be used as shown in the example below.+# +# packages:+# - some-directory+# - https://example.com/foo/bar/baz-0.0.2.tar.gz+# - location:+# git: https://github.com/commercialhaskell/stack.git+# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a+# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a+# extra-dep: true+# subdirs:+# - auto-update+# - wai+# +# A package marked 'extra-dep: true' will only be built if demanded by a+# non-dependency (i.e. a user package), and its test suites and benchmarks+# will not be run. This is useful for tweaking upstream packages.+packages:+- '.'+# Dependency packages to be pulled from upstream that are not in the resolver+# (e.g., acme-missiles-0.3)+extra-deps: []++# Override default flag values for local packages and extra-deps+flags: {}++# Extra package databases containing global packages+extra-package-dbs: []++# Control whether we use the GHC we find on the path+# system-ghc: true+# +# Require a specific version of stack, using version ranges+# require-stack-version: -any # Default+# require-stack-version: ">=1.0"+# +# Override the architecture used by stack, especially useful on Windows+# arch: i386+# arch: x86_64+# +# Extra directories used by stack for building+# extra-include-dirs: [/path/to/dir]+# extra-lib-dirs: [/path/to/dir]+# +# Allow a newer minor version of GHC than the snapshot specifies+# compiler-check: newer-minor