commutative-0.0.2: Commutative binary operations.

Safe HaskellNone
LanguageHaskell2010

Data.Commutative

Synopsis

Documentation

class Commutative a where Source #

Methods

commute Source #

Arguments

:: a 
-> a 
-> a

Abelian magma - x commute y == y commute x. Note that the commutative behaviour should be embedded in the instance. For distinguished commutes, more information is needed - like a predicate as is the case for commuteVia and commuteViaM.

Instances
Commutative () Source # 
Instance details

Defined in Data.Commutative

Methods

commute :: () -> () -> () Source #

Commutative All Source # 
Instance details

Defined in Data.Commutative

Methods

commute :: All -> All -> All Source #

Commutative Any Source # 
Instance details

Defined in Data.Commutative

Methods

commute :: Any -> Any -> Any Source #

Num a => Commutative (Sum a) Source # 
Instance details

Defined in Data.Commutative

Methods

commute :: Sum a -> Sum a -> Sum a Source #

Num a => Commutative (Product a) Source # 
Instance details

Defined in Data.Commutative

Methods

commute :: Product a -> Product a -> Product a Source #

Commutative (OneOf a) Source # 
Instance details

Defined in Data.Commutative

Methods

commute :: OneOf a -> OneOf a -> OneOf a Source #

Commutative (CommEndo a) Source # 
Instance details

Defined in Data.Commutative

Methods

commute :: CommEndo a -> CommEndo a -> CommEndo a Source #

(<~>) :: Commutative a => a -> a -> a Source #

class Commutative a => CommutativeId a where Source #

Methods

cempty Source #

Arguments

:: a

Identity element - x commute cempty == cempty commute x == x

Instances
CommutativeId () Source # 
Instance details

Defined in Data.Commutative

Methods

cempty :: () Source #

CommutativeId All Source # 
Instance details

Defined in Data.Commutative

Methods

cempty :: All Source #

CommutativeId Any Source # 
Instance details

Defined in Data.Commutative

Methods

cempty :: Any Source #

Num a => CommutativeId (Sum a) Source # 
Instance details

Defined in Data.Commutative

Methods

cempty :: Sum a Source #

Num a => CommutativeId (Product a) Source # 
Instance details

Defined in Data.Commutative

Methods

cempty :: Product a Source #

CommutativeId (OneOf a) Source # 
Instance details

Defined in Data.Commutative

Methods

cempty :: OneOf a Source #

CommutativeId (CommEndo a) Source # 
Instance details

Defined in Data.Commutative

Methods

cempty :: CommEndo a Source #

commuteVia :: Bool -> (a -> a -> a) -> a -> a -> a Source #

flip when False - simple & pure "predicative" commute.

commuteViaF :: Functor f => f Bool -> (a -> a -> a) -> a -> a -> f a Source #

Lifted predicative behaviour.

newtype CommEndo a Source #

Endomorphisms commutative over composition. Warning: The Commutative instance uses unsafePerformIO to randomly pick the order.

Constructors

CommEndo 

Fields

Instances
CommutativeId (CommEndo a) Source # 
Instance details

Defined in Data.Commutative

Methods

cempty :: CommEndo a Source #

Commutative (CommEndo a) Source # 
Instance details

Defined in Data.Commutative

Methods

commute :: CommEndo a -> CommEndo a -> CommEndo a Source #

newtype OneOf a Source #

In the case of two Just values, the commutative instance randomly chooses one of them. Warning: The Commutative instance uses unsafePerformIO to randomly pick the order.

Constructors

OneOf 

Fields

Instances
Eq a => Eq (OneOf a) Source # 
Instance details

Defined in Data.Commutative

Methods

(==) :: OneOf a -> OneOf a -> Bool #

(/=) :: OneOf a -> OneOf a -> Bool #

Show a => Show (OneOf a) Source # 
Instance details

Defined in Data.Commutative

Methods

showsPrec :: Int -> OneOf a -> ShowS #

show :: OneOf a -> String #

showList :: [OneOf a] -> ShowS #

CommutativeId (OneOf a) Source # 
Instance details

Defined in Data.Commutative

Methods

cempty :: OneOf a Source #

Commutative (OneOf a) Source # 
Instance details

Defined in Data.Commutative

Methods

commute :: OneOf a -> OneOf a -> OneOf a Source #

pick1 :: a -> a -> a Source #