commutative-0.0.1.4: 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.

(<~>) :: 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

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

appCommEndo :: a -> a
 

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

getOneOf :: Maybe a
 

pick1 :: a -> a -> a Source