News for hackers. Stuff that matters.
Re:Haskell People by ostochast on Saturday September 30, 2017 @02:50PM (#15374411)
For some people it is easier to understand a concept, especialy an abstract one, if they are given a few examples. For those people:

A monoid is a set and an binary operation on the elements of that set with the following properties:

1.The operation acts on two elements of the set to produce another elemenent of that set(closure).

Examples:

You have a set od natural numbers {0,1,2,3..} with standard addition. Whichever two natural numbers you choose to add you will get a natural number back.

A set of MxN matrices and matrix addition. If A and B are two MxN matrices A+B is a MxN matrix.

2.The order in which the operations are performed does not matter(associativity). So for all elements of our set a,b and c and the operation +:

a+(b+c)=(a+b)+c

must be valid.

Examples:

Let L be a set of strings and + concatenation. "Just"+(" an "+ "example")=("Just"+" an ")+"example"

Vector addition over vectors of same dimension.

3.There is an element(unique!) in the set which when applied to any element of the set returns that element(identity, neutral element).

e+a=a+e=a

e is identity

Examples:

0 is identity for standard addition: 0+1=1, 4+0=4

1 is identity for standard multplication: 1*7=7

""(empty string) is identity for string concatenation

There are no comments on this comment yet.