roam/20220312165500-semigroup.org
2022-03-16 19:56:10 -04:00

22 lines
1 KiB
Org Mode

:PROPERTIES:
:ID: b22a1c70-02a7-49ce-b5e7-407f1064cd0c
:END:
#+title: Semigroup
In [[id:9e68d422-cced-4177-96d1-90f777b9a493][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 [[id:9ac78677-2602-4a06-af0a-4ed82e98a9b6][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 [[id:434ee61c-4461-424f-8dba-5c86ddb06c3c][Monoid]] type class in Haskell, as it was introduced to
the language prior to Semigroup, and were given those names as the most common
[[id:434ee61c-4461-424f-8dba-5c86ddb06c3c][Monoid]] is a list.
#+caption: Semigroup functions in Haskell
#+begin_src haskell :exports code
(<>) :: Semigroup a => a -> a -> a
mappend :: Monoid a => a -> a -> a
mconcat :: Monoid a => [a] -> a
#+end_src