License | BSD-style (see the file LICENSE) |
---|---|
Maintainer | sjoerd@w3future.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
A free functor is left adjoint to a forgetful functor. In this package the forgetful functor forgets class constraints.
Synopsis
- newtype Free c a = Free {
- runFree :: forall b. c b => (a -> b) -> b
- deriveFreeInstance :: Name -> Q [Dec]
- deriveInstances :: Name -> Q [Dec]
- unit :: a -> Free c a
- rightAdjunct :: c b => (a -> b) -> Free c a -> b
- counit :: c a => Free c a -> a
- leftAdjunct :: (Free c a -> b) -> a -> b
- transform :: (forall r. c r => (b -> r) -> a -> r) -> Free c a -> Free c b
- unfold :: (b -> Coproduct c b a) -> b -> Free c a
- convert :: (c (f a), Applicative f) => Free c a -> f a
- convertClosed :: c r => Free c Void -> r
- newtype Extract a = Extract {
- getExtract :: a
- newtype Duplicate f a = Duplicate {
- getDuplicate :: f (f a)
- type Coproduct c m n = Free c (Either m n)
- coproduct :: c r => (m -> r) -> (n -> r) -> Coproduct c m n -> r
- inL :: m -> Coproduct c m n
- inR :: n -> Coproduct c m n
- type InitialObject c = Free c Void
- initial :: c r => InitialObject c -> r
Documentation
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.
Instances
Monad (Free c) Source # | |
Functor (Free c) Source # | |
Applicative (Free c) Source # | |
(forall (f :: Type -> Type) x. Applicative f => c (Ap f (Free c x))) => Foldable (Free c) Source # | |
Defined in Data.Functor.Free 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 # elem :: Eq a => a -> Free c a -> Bool # maximum :: Ord a => Free c a -> a # minimum :: Ord a => Free c a -> a # | |
(forall (f :: Type -> Type) x. Applicative f => c (Ap f (Free c x))) => Traversable (Free c) Source # | |
(forall x. c (Extract x), forall x. c (Duplicate (Free c) x)) => Comonad (Free c) Source # | |
(c ~=> Floating, c (Free c a)) => Floating (Free c a) Source # | |
Defined in Data.Functor.Free 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 # 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 # | |
(c ~=> Fractional, c (Free c a)) => Fractional (Free c a) Source # | |
(c ~=> Num, c (Free c a)) => Num (Free c a) Source # | |
(Show a, c ShowsPrec) => Show (Free c a) Source # | |
(c ~=> Semigroup, c (Free c a)) => Semigroup (Free c a) Source # | |
(c ~=> Monoid, c (Free c a)) => Monoid (Free c a) Source # | |
rightAdjunct :: c b => (a -> b) -> Free c a -> b Source #
rightAdjunct
is the destructor of
values.Free
c
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)
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
Extract | |
|
newtype Duplicate f a Source #
Duplicate | |
|
Coproducts
type Coproduct c m n = Free c (Either m n) Source #
Products of Monoid
s are Monoid
s themselves. But coproducts of Monoid
s are not.
However, the free Monoid
applied to the coproduct is a Monoid
, and it is the coproduct in the category of Monoid
s.
This is also called the free product, and generalizes to any algebraic class.
type InitialObject c = Free c Void Source #
initial :: c r => InitialObject c -> r Source #