numhask
Safe HaskellNone
LanguageGHC2024

NumHask.Algebra.Bimonoid

Description

Bimonoid structure at the value level.

In linear logic the exponentials !A and ?A license the structural rules of contractionweakening and cocontractioncoweakening. These are not properties of the value itself in isolation; they are algebraic structure on how values may be used. Because functions are first-class, that structure can be made explicit as type classes.

  • Copyable is the ! fragment: values may be duplicated and discarded.
  • Mergeable is the ? fragment: values may be combined with a unit.

For the function arrow (->) the cartesian structure gives a canonical Copyable instance, while Mergeable is pointwise whenever the codomain is mergeable.

Synopsis

Documentation

class Copyable a where Source #

A cocommutative comonoid in the category of Haskell functions.

This is the value-level content of the linear-logic exponential !A: the value may be copied (contraction) and discarded (weakening).

Methods

copy :: a -> (a, a) Source #

Duplicate a value.

discard :: a -> () Source #

Discard a value.

Instances

Instances details
Copyable a Source #

In the category of Haskell functions every object carries a canonical cocommutative comonoid structure: the diagonal and the terminal map.

Instance details

Defined in NumHask.Algebra.Bimonoid

Methods

copy :: a -> (a, a) Source #

discard :: a -> () Source #

class Mergeable a where Source #

A commutative monoid in the category of Haskell functions.

This is the value-level content of the linear-logic exponential ?A: values may be merged (cocontraction) and introduced from nothing (coweakening).

Methods

merge :: (a, a) -> a Source #

Combine two values.

mergeZero :: () -> a Source #

The unit value, introduced from the terminal object ().

Instances

Instances details
Mergeable () Source #

Unit merges trivially.

Instance details

Defined in NumHask.Algebra.Bimonoid

Methods

merge :: ((), ()) -> () Source #

mergeZero :: () -> () Source #

Mergeable Bool Source #

Booleans merge by disjunction.

Instance details

Defined in NumHask.Algebra.Bimonoid

Methods

merge :: (Bool, Bool) -> Bool Source #

mergeZero :: () -> Bool Source #

Additive a => Mergeable a Source #

Numeric types merge by addition.

This generic instance covers every Additive carrier; the unit is the additive identity zero.

Instance details

Defined in NumHask.Algebra.Bimonoid

Methods

merge :: (a, a) -> a Source #

mergeZero :: () -> a Source #

Ord a => Mergeable (Set a) Source #

Sets merge by union.

Instance details

Defined in NumHask.Algebra.Bimonoid

Methods

merge :: (Set a, Set a) -> Set a Source #

mergeZero :: () -> Set a Source #

Mergeable b => Mergeable (a -> b) Source #

Function merging is pointwise.

Instance details

Defined in NumHask.Algebra.Bimonoid

Methods

merge :: (a -> b, a -> b) -> a -> b Source #

mergeZero :: () -> a -> b Source #