free-functors-1.1.2: Free functors, adjoint to functors that forget class constraints.
LicenseBSD-style (see the file LICENSE)
Maintainersjoerd@w3future.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Functor.Free

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 class c.

Free c a is basically an expression tree with operations from class c and variables/placeholders of type a, created with unit. Monadic bind allows you to replace each of these variables with another sub-expression.

Constructors

Free 

Fields

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

Instances

Instances details
Monad (Free c) Source # 
Instance details

Defined in Data.Functor.Free

Methods

(>>=) :: Free c a -> (a -> Free c b) -> Free c b #

(>>) :: Free c a -> Free c b -> Free c b #

return :: a -> Free c a #

Functor (Free c) Source # 
Instance details

Defined in Data.Functor.Free

Methods

fmap :: (a -> b) -> Free c a -> Free c b #

(<$) :: a -> Free c b -> Free c a #

Applicative (Free c) Source # 
Instance details

Defined in Data.Functor.Free

Methods

pure :: a -> Free c a #

(<*>) :: Free c (a -> b) -> Free c a -> Free c b #

liftA2 :: (a -> b -> c0) -> Free c a -> Free c b -> Free c c0 #

(*>) :: Free c a -> Free c b -> Free c b #

(<*) :: Free c a -> Free c b -> Free c a #

(forall (f :: Type -> Type) x. Applicative f => c (Ap f (Free c x))) => Foldable (Free c) Source # 
Instance details

Defined in Data.Functor.Free

Methods

fold :: Monoid m => Free c m -> m #

foldMap :: Monoid m => (a -> m) -> Free c a -> m #

foldMap' :: Monoid m => (a -> m) -> Free c a -> m #

foldr :: (a -> b -> b) -> b -> Free c a -> b #

foldr' :: (a -> b -> b) -> b -> Free c a -> b #

foldl :: (b -> a -> b) -> b -> Free c a -> b #

foldl' :: (b -> a -> b) -> b -> Free c a -> b #

foldr1 :: (a -> a -> a) -> Free c a -> a #

foldl1 :: (a -> a -> a) -> Free c a -> a #

toList :: Free c a -> [a] #

null :: Free c a -> Bool #

length :: Free c a -> Int #

elem :: Eq a => a -> Free c a -> Bool #

maximum :: Ord a => Free c a -> a #

minimum :: Ord a => Free c a -> a #

sum :: Num a => Free c a -> a #

product :: Num a => Free c a -> a #

(forall (f :: Type -> Type) x. Applicative f => c (Ap f (Free c x))) => Traversable (Free c) Source # 
Instance details

Defined in Data.Functor.Free

Methods

traverse :: Applicative f => (a -> f b) -> Free c a -> f (Free c b) #

sequenceA :: Applicative f => Free c (f a) -> f (Free c a) #

mapM :: Monad m => (a -> m b) -> Free c a -> m (Free c b) #

sequence :: Monad m => Free c (m a) -> m (Free c a) #

(forall x. c (Extract x), forall x. c (Duplicate (Free c) x)) => Comonad (Free c) Source # 
Instance details

Defined in Data.Functor.Free

Methods

extract :: Free c a -> a #

duplicate :: Free c a -> Free c (Free c a) #

extend :: (Free c a -> b) -> Free c a -> Free c b #

c ~=> Floating => Floating (Free c a) Source # 
Instance details

Defined in Data.Functor.Free

Methods

pi :: Free c a #

exp :: Free c a -> Free c a #

log :: Free c a -> Free c a #

sqrt :: Free c a -> Free c a #

(**) :: Free c a -> Free c a -> Free c a #

logBase :: Free c a -> Free c a -> Free c a #

sin :: Free c a -> Free c a #

cos :: Free c a -> Free c a #

tan :: Free c a -> Free c a #

asin :: Free c a -> Free c a #

acos :: Free c a -> Free c a #

atan :: Free c a -> Free c a #

sinh :: Free c a -> Free c a #

cosh :: Free c a -> Free c a #

tanh :: Free c a -> Free c a #

asinh :: Free c a -> Free c a #

acosh :: Free c a -> Free c a #

atanh :: Free c a -> Free c a #

log1p :: Free c a -> Free c a #

expm1 :: Free c a -> Free c a #

log1pexp :: Free c a -> Free c a #

log1mexp :: Free c a -> Free c a #

c ~=> Fractional => Fractional (Free c a) Source # 
Instance details

Defined in Data.Functor.Free

Methods

(/) :: Free c a -> Free c a -> Free c a #

recip :: Free c a -> Free c a #

fromRational :: Rational -> Free c a #

c ~=> Num => Num (Free c a) Source # 
Instance details

Defined in Data.Functor.Free

Methods

(+) :: Free c a -> Free c a -> Free c a #

(-) :: Free c a -> Free c a -> Free c a #

(*) :: Free c a -> Free c a -> Free c a #

negate :: Free c a -> Free c a #

abs :: Free c a -> Free c a #

signum :: Free c a -> Free c a #

fromInteger :: Integer -> Free c a #

(Show a, c ShowsPrec) => Show (Free c a) Source # 
Instance details

Defined in Data.Functor.Free

Methods

showsPrec :: Int -> Free c a -> ShowS #

show :: Free c a -> String #

showList :: [Free c a] -> ShowS #

c ~=> Semigroup => Semigroup (Free c a) Source # 
Instance details

Defined in Data.Functor.Free

Methods

(<>) :: Free c a -> Free c a -> Free c a #

sconcat :: NonEmpty (Free c a) -> Free c a #

stimes :: Integral b => b -> Free c a -> Free c a #

c ~=> Monoid => Monoid (Free c a) Source # 
Instance details

Defined in Data.Functor.Free

Methods

mempty :: Free c a #

mappend :: Free c a -> Free c a -> Free c a #

mconcat :: [Free c a] -> Free c a #

deriveFreeInstance :: Name -> Q [Dec] Source #

Derive the instance of Free c a for the class c.

For example:

deriveFreeInstance ''Num

unit :: a -> Free c a Source #

unit allows you to create Free c values, together with the operations from the class c.

rightAdjunct :: c b => (a -> b) -> Free c a -> b Source #

rightAdjunct is the destructor of Free c values.

counit :: c a => Free c a -> a Source #

counit = rightAdjunct id

leftAdjunct :: (Free c a -> b) -> a -> b Source #

leftAdjunct f = f . unit

transform :: (forall r. c r => (b -> r) -> a -> r) -> Free c a -> Free c b Source #

transform f as = as >>= f unit
transform f . transform g = transform (g . f)

unfold :: (b -> Coproduct c b a) -> b -> Free c a Source #

unfold f = coproduct (unfold f) unit . f

inL and inR are useful here. For example, the following creates the list [1..10] as a Free Monoid:

unfold (b -> if b == 0 then mempty else inL (b - 1) <> inR b) 10

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

convert = rightAdjunct pure

convertClosed :: c r => Free c Void -> r Source #

convertClosed = rightAdjunct absurd

newtype Extract a Source #

Constructors

Extract 

Fields

newtype Duplicate f a Source #

Constructors

Duplicate 

Fields

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 -> r Source #

inL :: m -> Coproduct c m n Source #

inR :: n -> Coproduct c m n Source #

initial :: c r => InitialObject c -> r Source #

Orphan instances

(Applicative f, Floating a) => Floating (Ap f a) Source # 
Instance details

Methods

pi :: Ap f a #

exp :: Ap f a -> Ap f a #

log :: Ap f a -> Ap f a #

sqrt :: Ap f a -> Ap f a #

(**) :: Ap f a -> Ap f a -> Ap f a #

logBase :: Ap f a -> Ap f a -> Ap f a #

sin :: Ap f a -> Ap f a #

cos :: Ap f a -> Ap f a #

tan :: Ap f a -> Ap f a #

asin :: Ap f a -> Ap f a #

acos :: Ap f a -> Ap f a #

atan :: Ap f a -> Ap f a #

sinh :: Ap f a -> Ap f a #

cosh :: Ap f a -> Ap f a #

tanh :: Ap f a -> Ap f a #

asinh :: Ap f a -> Ap f a #

acosh :: Ap f a -> Ap f a #

atanh :: Ap f a -> Ap f a #

log1p :: Ap f a -> Ap f a #

expm1 :: Ap f a -> Ap f a #

log1pexp :: Ap f a -> Ap f a #

log1mexp :: Ap f a -> Ap f a #

(Applicative f, Fractional a) => Fractional (Ap f a) Source # 
Instance details

Methods

(/) :: Ap f a -> Ap f a -> Ap f a #

recip :: Ap f a -> Ap f a #

fromRational :: Rational -> Ap f a #