Hacker News new | past | comments | ask | show | jobs | submit login

So it sounds like a monoid is a:

Function of arity-2 (possibly expressed as an infix operator)

Which is closed over the set of values that are its arguments/parameters

For a domain (set of input values) which contains a value that converts the function into an identity function when used.

E.g. -

Addition over real numbers (or integers...), becomes an identity function when one arg is 0

Multiplication over real numbers (or integers...), becomes an identity function when one arg is 1

Something along that line?

I guess that makes it useful for a fold/reduce type function where the final result is the same type as the input stream, and the initial value can be identified as a known default.




Exactly right, but for omitting associativity (which, as noted elsewhere, mightybyte skipped).


Yep, it sounds like you pretty much have it. In addition to the two examples you mention, here are some other examples of monoids:

Lists under concatenation Booleans under AND Booleans under OR Numbers under max Numbers under min




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: