monoid-subclasses-0.4.0.1: Subclasses of Monoid

Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Monoid.Instances.Stateful

Description

This module defines the monoid transformer data type Stateful.

> let s = setState [4] $ pure "data" :: Stateful [Int] String
> s
Stateful ("data",[4])
> factors s
[Stateful ("d",[]),Stateful ("a",[]),Stateful ("t",[]),Stateful ("a",[]),Stateful ("",[4])]

Synopsis

Documentation

newtype Stateful a b Source

Stateful a b is a wrapper around the Monoid b that carries the state a along. The state type a must be a monoid as well if Stateful is to be of any use. In the FactorialMonoid and TextualMonoid class instances, the monoid b has the priority and the state a is left for the end.

Constructors

Stateful (b, a) 

extract :: Stateful a b -> b Source

state :: Stateful a b -> a Source

setState :: a -> Stateful a b -> Stateful a b Source