Typeclass Laws
⚖ effect-ts-laws
Typeclass
Law
Predicate
Equivalence
transitivity$a=b ∧ b=c$$⇒$$a=c$
symmetry
$a=b$$⇔$$b=a$
reflexivity$a$$=$$a$
Order
transitivity$a≤b ∧ b≤c$$⇒$$a≤c$
connectivity$a≤b$$∨$$b≤a$
reflexivity$a$$≤$$a$
complement consistency
$a≤b$
$⇒$
$a \ngtr b$
equivalence consistency
$a≤b ∧ b≤a$
$⇒$
$a=b$
Bounded
lower bounded
$a$$≥$
$\minBound$
upper bounded
$a$
$≤$
$\maxBound$
Semigroup
associativity
$(a ⊕ b) ⊕ c$
$=$
$a ⊕ (b ⊕ c)$
combineMany associativity
$\combineMany(a, [b, c])$
$=$
$a ⊕ (b ⊕ c)$
Monoid
left identity$∅ ⊕ a$$=$$a$
right identity$a ⊕ ∅$$=$$a$
Invariant
identity$\imap\left(\id, \id\right)$$=$$\id$
composition
$\imap(ab, ba) \∘ \imap(bc, cb)$
$=$
$\imap(bc \∘ ab, ba \∘ cb)$
Contravariant
identity$\contramap(\id)$$=$$\id$
composition
$\contramap(ba) \∘ \contramap(cb)$
$=$
$\contramap(ba \∘ cb)$
Covariant
identity$\map(\id)$$=$$\id$
composition
$\map(ab) \∘ \map(bc)$
$=$
$\map(bc \∘ ab)$
Applicative
identity$\id \▹ \of \▹ \ap(a)$$=$$a$
homomorphism
$ab \▹ \of \▹ (a \▹ \of \▹ \ap)$
$=$
$a \▹ ab \▹ \of$
associative composition
$\fbc \▹ \map(\compose) \▹ \ap(\fab) \▹ \ap(\fa)$
$=$
$\fbc \▹ \ap\(\fab \▹ \ap(\fa))$
interchange
$\fab \▹ \ap\(\of(a)\)$
$=$
$a \▹ \apply \▹ \of \▹ \ap(\fab)$
map consistency
$\fa \▹ \map(ab)$
$=$
$ab \▹ \of \▹ \ap(\fa)$
product consistency
$\fab \▹ \ap(\fa)$
$=$
$\product(\fab, \fa) \▹ \map\(([ab, a]) ⇒ ab(a)\)$
flatMap consistency
$\ap(\fa)$
$=$
$\flatMap\(ab ⇒ \!\map(\fa, ab)\)$
Monad
left identity
$\of \∘ \flatMap(\afb)$
$=$
$\afb$
right identity$\flatMap(\of)$$=$$\id$
associativity
$\flatMap(\afb) \∘ \flatMap(\bfc)$
$=$
$\flatMap\(\flatMap(\bfc) \∘ \afb\)$
map consistency
$\map(ab)$
$=$
$\flatMap(\of \∘ ab)$
SemiAlternative
associativity
$(\fa_1 ⊕ \fa_2) ⊕ \fa_3$
$=$$\fa_1 ⊕ (\fa_2 ⊕ \fa_3)$
coproductMany associativity
$\coproductMany(\fa_1, [\fa_2, \fa_3])$
$=$$\fa_1 ⊕ (\fa_2 ⊕ \fa_3)$
Alternative
left identity$∅ ⊕ \fa$$=$$\fa$
right identity
$\fa ⊕ ∅$
$=$
$\fa$
coproductAll zero
$\coproductAll\:\!\raisebox{0.5pt}{([\,])}$
$=$
$∅$
Traversable
identity$\Id.\traverse(\id)$$=$$\id$
composition
$\G.\map\(\H.\traverse(bhc)\) \∘ \G.\traverse(agb)$
$=$
$\GH.\traverse\(\G.\map(bhc) \∘ agb\)$
map consistency
$\F.\map(ab)$
$=$
$\Id.\traverse(ab)$