FR
PréludeChargé par défaut — aucun import nécessaire.

Semigroup and Monoid — associative combination

Synopsis
interface Semigroup a where
(<>) : a -> a -> a

A type with an associative binary operation (<>). (++) (below) is a synonym, conventional on lists and strings.

Instances : LazyList, List, String
(++) : Semigroup a => a -> a -> a

(++) is a synonym for (<>) — conventional on lists and strings, where the concrete type is known. In polymorphic code, prefer (<>).

interface Semigroup a => Monoid a where
mempty : a

A semigroup with an identity element mempty. Laws: mempty <> x == x and x <> mempty == x.

Instances : LazyList, List, String
concat : Monoid m => List m -> m

Concatenate a list of monoid values: concat [a, b, c] = a <> b <> c, and concat [] = mempty. Works over any Monoid — lists of lists, lists of strings, … — combining the elements in order with (<>), using mempty as the result for the empty list. concat ["a", "b", "c"] = "abc" concat [[1], [2, 3]] = [1, 2, 3]