algebraic-classes-0.9: Conversions between algebraic classes and F-algebras.

Data.Algebra.Internal

Description

Synopsis

# Documentation

type family Signature (c :: * -> Constraint) :: * -> * Source #

The signature datatype for the class c.

class Traversable f => AlgebraSignature f where Source #

Minimal complete definition

evaluate

Associated Types

type Class f :: * -> Constraint Source #

The class for which f is the signature.

Methods

evaluate :: Class f b => f b -> b Source #

Translate the operations of the signature to method calls of the class.

class Algebra f a where Source #

Minimal complete definition

algebra

Methods

algebra :: AlgebraSignature f => f a -> a Source #

An algebra f a -> a corresponds to an instance of a of the class Class f. In some cases, for example for tuple types, you can give an algebra generically for every signature:

instance (Class f m, Class f n) => Algebra f (m, n) where
algebra fmn = (evaluate (fmap fst fmn), evaluate (fmap snd fmn))

Instances

 Algebra f () Source # Methodsalgebra :: f () -> () Source # Class f b => Algebra f (STM b) Source # Methodsalgebra :: f (STM b) -> STM b Source # Class f b => Algebra f (Maybe b) Source # Methodsalgebra :: f (Maybe b) -> Maybe b Source # Class f b => Algebra f (IO b) Source # Methodsalgebra :: f (IO b) -> IO b Source # Class f b => Algebra f (Either a b) Source # Methodsalgebra :: f (Either a b) -> Either a b Source # Class f b => Algebra f (a -> b) Source # Methodsalgebra :: f (a -> b) -> a -> b Source # (Class f m, Class f n) => Algebra f (m, n) Source # Methodsalgebra :: f (m, n) -> (m, n) Source # (Monoid m, Class f b) => Algebra f (Const * m b) Source # Methodsalgebra :: f (Const * m b) -> Const * m b Source #

algebraA :: (Applicative g, Class f b, AlgebraSignature f) => f (g b) -> g b Source #

If you just want to applicatively lift existing instances, you can use this default implementation of algebra.