A module to define generic functions for monoid.
For instance, we defined generic concat
in this module using Monoid
type as follows.
concat : Monoid a -> List a -> a
concat m =
List.foldr (append m) (empty m)
concat string ["foo", "bar", "baz"]
--> "foobarbaz"
concat list [[1, 2, 3], [4, 5], [6]]
--> [1, 2, 3, 4, 5, 6]
concat sum [Sum 1, Sum 2, Sum 3, Sum 4] -- 1 + 2 + 3 + 4
--> Sum 10
concat sum <| List.map Sum [1, 2, 3, 4] -- 1 + 2 + 3 + 4
--> Sum 10
concat product <| List.map Product [1, 2, 3, 4] -- 1 * 2 * 3 * 4
--> Product 24
Main type.
Monoid
under addition
Monoid
under multiplication.
monoid : a -> (a -> a -> a) -> Monoid a
Constructor for Monoid
.
empty : Monoid a -> a
Take the identity element of a monoid.
append : Monoid a -> a -> a -> a
Take the way to append a monoids.
concat : Monoid a -> List a -> a
Concatenate list of monoid.
string : Monoid String
Monoid
type for String
.
sum : Monoid (Sum number)
Monoid
type for Sum
.
product : Monoid (Product number)
Monoid
type for Product
.
list : Monoid (List a)
Monoid
type for List
.
array : Monoid (Array a)
Monoid
type for Array
.
dict : Monoid (Dict comparable a)
Monoid
type for Dict
.
set : Monoid (Set comparable)
Monoid
type for Set
.
cmd : Monoid (Platform.Cmd.Cmd comparable)
Monoid
type for Cmd
.
sub : Monoid (Platform.Sub.Sub comparable)
Monoid
type for Sub
.