free-functors-0.4.1: Provides free functors that are adjoint to functors that forget class constraints.

Portabilitynon-portable
Stabilityexperimental
Maintainersjoerd@w3future.com
Safe HaskellNone

Data.Functor.Free

Contents

Description

A free functor is left adjoint to a forgetful functor. In this package the forgetful functor forgets class constraints.

Synopsis

Documentation

newtype Free c a Source

The free functor for constraint c.

Constructors

Free 

Fields

runFree :: forall b. c b => (a -> b) -> b
 

Instances

~ (* -> Constraint) c (Class f) => Algebra f (Free c a) 
ForallF c (Free c) => Monad (Free c) 
Functor (Free c) 
Applicative (Free c) 
ForallT c (LiftAFree c) => Foldable (Free c) 
ForallT c (LiftAFree c) => Traversable (Free c) 
(ForallF c Identity, ForallF c (Free c), ForallF c (Compose (Free c) (Free c))) => Comonad (Free c) 

unit :: a -> Free c aSource

rightAdjunct :: c b => (a -> b) -> Free c a -> bSource

rightAdjunctF :: ForallF c f => (a -> f b) -> Free c a -> f bSource

rightAdjunctT :: ForallT c t => (a -> t f b) -> Free c a -> t f bSource

counit :: c a => Free c a -> aSource

counit = rightAdjunct id

leftAdjunct :: (Free c a -> b) -> a -> bSource

leftAdjunct f = f . unit

newtype LiftAFree c f a Source

Constructors

LiftAFree 

Fields

getLiftAFree :: f (Free c a)
 

Instances

(Applicative f, ~ (* -> Constraint) c (Class s)) => Algebra s (LiftAFree c f a) 

convert :: (c (f a), Applicative f) => Free c a -> f aSource

convertClosed :: c r => Free c Void -> rSource

Coproducts

type Coproduct c m n = Free c (Either m n)Source

Products of Monoids are Monoids themselves. But coproducts of Monoids are not. However, the free Monoid applied to the coproduct is a Monoid, and it is the coproduct in the category of Monoids. This is also called the free product, and generalizes to any algebraic class.

coproduct :: c r => (m -> r) -> (n -> r) -> Coproduct c m n -> rSource

inL :: m -> Coproduct c m nSource

inR :: n -> Coproduct c m nSource

initial :: c r => InitialObject c -> rSource