roam/20220312165500-semigroup.org

1.0 KiB

Semigroup

In Software Development, a Semigroup is a category of types such that two values of the type can be combined associatively to create a new value of the same type.

In Haskell, the function to combine two semigroup values is mappend, also available as the infix operator <>. mconcat is also provided for combining a list of semigroup values into a single new value. The mappend and mconcat functions are part of the Monoid type class in Haskell, as it was introduced to the language prior to Semigroup, and were given those names as the most common Monoid is a list.

  (<>) :: Semigroup a => a -> a -> a
  mappend :: Monoid a => a -> a -> a
  mconcat :: Monoid a => [a] -> a
Semigroup functions in Haskell