Semigroup

SemiGroup 幺半群

Type signature:

// C#定义SemiGroup:
public interface SemiGroup<T> {
    T Append(T thingToAppend);
}

// 用Haskell定义:
class SemiGroup a where
    append :: a-> a -> a

// Haskell实现的String with append:
instance Semigroup String where
    append a b = a ++ b

__Law__s are additional properties that need to be satisfied beyond what’s expressed in the type signature.

Laws of Semigroup:

Append is associative.

Append(Append(a, b), c) == Append(a, Append(b, c))

(a <> b) <>> c == a <> (b <> c)

Usage/Feature of semigroup:

1)Partition friendly

2)Incremental