weighted-regexp- Weighted Regular Expression Matcher

MaintainerSebastian Fischer <mailto:mail@sebfisch.de>



This library provides a type class for semirings and instances for standard data types.



class Eq s => Semiring s whereSource

A semiring is an additive commutative monoid with identity zero:

         a .+. b  ==  b .+. a
      zero .+. a  ==  a
 (a .+. b) .+. c  ==  a .+. (b .+. c)

A semiring is a multiplicative monoid with identity one:

        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)

zero annihilates a semiring with respect to multiplication:

 zero .*. a  ==  zero
 a .*. zero  ==  zero

All laws should hold with respect to the required Eq instance.

For example, the Booleans form a semiring.

  • False is an identity of disjunction which is commutative and associative,
  • True is an identity of conjunction which is associative,
  • conjunction distributes over disjunction, and
  • False annihilates the Booleans with respect to conjunction.


zero :: sSource

one :: sSource

(.+.) :: s -> s -> sSource

(.*.) :: s -> s -> sSource

fromBool :: Semiring s => Bool -> sSource

Auxiliary function to convert Booleans to an arbitrary semiring.

data Numeric a Source

Wrapper for numeric types.

Every numeric type that satisfies the semiring laws (as all predefined numeric types do) is a semiring.




getNumeric :: a


Num a => Weight c (Int, c) (Numeric a) 
Eq a => Eq (Numeric a) 
Num a => Num (Numeric a) 
(Num a, Show a) => Show (Numeric a) 
Num a => Semiring (Numeric a)