monoid: Creates the monoid binary operator

Description Usage Arguments Value Note Author(s) References See Also Examples

View source: R/monoid.R

Description

Creates the monoid binary operator for a monoid in the Continuation category.

Usage

1
monoid(op)

Arguments

op

The binary operator to be be insert in the monoid (multiplication).

Value

It returns a function of the type h(f, g) where f and g must be elements of the monoid and objects in the Continuation category. The function h will return a function of the type t(x, ret) which can be used in the Continuation category.

Note

The developer must make sure that the function f and g are elements of a monoid and of the Continuation category. The developer must also ensure that the operator op is the monoid's binary operator.

Author(s)

Matteo Provenzano
http://www.alephdue.com

References

https://en.wikipedia.org/wiki/Monoid_(category_theory)

See Also

do

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# A list is a monoid
replicate.10 <- function(x, ret) {
  ret(rep(x, 10))
}

# concatenation is the binary operator for the list monoid
# the empty list is the unit
`%et%` <- monoid(c)

replicate.20 <- do(replicate.10 %et% replicate.10)

# returns a list of 20 "a"s
replicate.20("a")

matteoprovenzano/kriens-r documentation built on May 21, 2019, 12:59 p.m.