control-monad-free-0.6.1: Free monads and monad transformers

Safe Haskell | Safe
Language | Haskell98

Control.Monad.Free

Contents

- Free Monads
- Monad Morphisms
- Free Monad Transformers
- Translate between Free monad and Free monad transformer computations

Synopsis

- module Control.Monad
- class (Functor f, Monad m) => MonadFree f m where
- data Free f a
  - = Impure (f (Free f a))
  - | Pure a
- isPure :: Free t1 t -> Bool
- isImpure :: Free t1 t -> Bool
- foldFree :: Functor f => (a -> b) -> (f b -> b) -> Free f a -> b
- evalFree :: (a -> b) -> (f (Free f a) -> b) -> Free f a -> b
- mapFree :: (Functor f, Functor g) => (f (Free g a) -> g (Free g a)) -> Free f a -> Free g a
- mapFreeM :: (Traversable f, Functor g, Monad m) => (f (Free g a) -> m (g (Free g a))) -> Free f a -> m (Free g a)
- mapFreeM' :: (Functor f, Traversable g, Monad m) => (forall a. f a -> m (g a)) -> Free f a -> m (Free g a)
- foldFreeM :: (Traversable f, Monad m) => (a -> m b) -> (f b -> m b) -> Free f a -> m b
- induce :: (Functor f, Monad m) => (forall a. f a -> m a) -> Free f a -> m a
- newtype FreeT f m a = FreeT {
  - unFreeT :: m (Either a (f (FreeT f m a)))
  }
- foldFreeT :: (Traversable f, Monad m) => (a -> m b) -> (f b -> m b) -> FreeT f m a -> m b
- foldFreeT' :: (Traversable f, Monad m) => (a -> b) -> (f b -> b) -> FreeT f m a -> m b
- mapFreeT :: (Functor f, Functor m) => (forall a. m a -> m' a) -> FreeT f m a -> FreeT f m' a
- foldFreeA :: (Traversable f, Applicative m) => (a -> m b) -> m (f b -> b) -> Free f a -> m b
- mapFreeA :: (Traversable f, Functor g, Applicative m) => m (f (Free g a) -> g (Free g a)) -> Free f a -> m (Free g a)
- trans :: MonadFree f m => Free f a -> m a
- trans' :: (Functor f, Monad m) => m (Free f a) -> FreeT f m a
- untrans :: (Traversable f, Monad m) => FreeT f m a -> m (Free f a)
- liftFree :: (Functor f, Monad m) => (a -> Free f b) -> a -> FreeT f m b

# Documentation

module Control.Monad

# Free Monads

class (Functor f, Monad m) => MonadFree f m where #

This type class generalizes over encodings of Free Monads.

Minimal complete definition

free, wrap

Methods

free :: m a -> m (Either a (f (m a))) #

wrap :: f (m a) -> m a #

Instances

Functor f => MonadFree f (Free f) # |
Methods free :: Free f a -> Free f (Either a (f (Free f a))) # wrap :: f (Free f a) -> Free f a #
(Monad m, Functor f) => MonadFree f (C (FreeT f m)) # |
Methods free :: C (FreeT f m) a -> C (FreeT f m) (Either a (f (C (FreeT f m) a))) # wrap :: f (C (FreeT f m) a) -> C (FreeT f m) a #
Functor f => MonadFree f (C (Free f)) # |
Methods free :: C (Free f) a -> C (Free f) (Either a (f (C (Free f) a))) # wrap :: f (C (Free f) a) -> C (Free f) a #
(Functor f, Monad m) => MonadFree f (FreeT f m) # |
Methods free :: FreeT f m a -> FreeT f m (Either a (f (FreeT f m a))) # wrap :: f (FreeT f m a) -> FreeT f m a #

data Free f a #

Constructors

Impure (f (Free f a)) |
Pure a |

Instances

Functor f => MonadFree f (Free f) # |
Methods free :: Free f a -> Free f (Either a (f (Free f a))) # wrap :: f (Free f a) -> Free f a #
Functor f => MonadFree f (C (Free f)) # |
Methods free :: C (Free f) a -> C (Free f) (Either a (f (C (Free f) a))) # wrap :: f (C (Free f) a) -> C (Free f) a #
Functor f => Monad (Free f) # |
Methods (>>=) :: Free f a -> (a -> Free f b) -> Free f b # (>>) :: Free f a -> Free f b -> Free f b # return :: a -> Free f a # fail :: String -> Free f a #
Functor f => Functor (Free f) # |
Methods fmap :: (a -> b) -> Free f a -> Free f b # (<$) :: a -> Free f b -> Free f a #
Functor f => Applicative (Free f) # |
Methods pure :: a -> Free f a # (<*>) :: Free f (a -> b) -> Free f a -> Free f b # (*>) :: Free f a -> Free f b -> Free f b # (<*) :: Free f a -> Free f b -> Free f a #
(Functor f, Foldable f) => Foldable (Free f) # |
Methods fold :: Monoid m => Free f m -> m # foldMap :: Monoid m => (a -> m) -> Free f a -> m # foldr :: (a -> b -> b) -> b -> Free f a -> b # foldr' :: (a -> b -> b) -> b -> Free f a -> b # foldl :: (b -> a -> b) -> b -> Free f a -> b # foldl' :: (b -> a -> b) -> b -> Free f a -> b # foldr1 :: (a -> a -> a) -> Free f a -> a # foldl1 :: (a -> a -> a) -> Free f a -> a # toList :: Free f a -> [a] # null :: Free f a -> Bool # length :: Free f a -> Int # elem :: Eq a => a -> Free f a -> Bool # maximum :: Ord a => Free f a -> a # minimum :: Ord a => Free f a -> a # sum :: Num a => Free f a -> a # product :: Num a => Free f a -> a #
Traversable f => Traversable (Free f) # |
Methods traverse :: Applicative f => (a -> f b) -> Free f a -> f (Free f b) # sequenceA :: Applicative f => Free f (f a) -> f (Free f a) # mapM :: Monad m => (a -> m b) -> Free f a -> m (Free f b) # sequence :: Monad m => Free f (m a) -> m (Free f a) #
Eq1 f => Eq1 (Free f) # |
Methods (==#) :: Eq a => Free f a -> Free f a -> Bool #
Ord1 f => Ord1 (Free f) # |
Methods compare1 :: Ord a => Free f a -> Free f a -> Ordering #
(Eq a, Eq1 f) => Eq (Free f a) # |
Methods (==) :: Free f a -> Free f a -> Bool # (/=) :: Free f a -> Free f a -> Bool #
(Ord a, Ord1 f) => Ord (Free f a) # |
Methods compare :: Free f a -> Free f a -> Ordering # (<) :: Free f a -> Free f a -> Bool # (<=) :: Free f a -> Free f a -> Bool # (>) :: Free f a -> Free f a -> Bool # (>=) :: Free f a -> Free f a -> Bool # max :: Free f a -> Free f a -> Free f a # min :: Free f a -> Free f a -> Free f a #
(Show a, Show1 f) => Show (Free f a) # |
Methods showsPrec :: Int -> Free f a -> ShowS # show :: Free f a -> String # showList :: [Free f a] -> ShowS #
Generic (Free f a) # |
Associated Types type Rep (Free f a) :: * -> * # Methods from :: Free f a -> Rep (Free f a) x # to :: Rep (Free f a) x -> Free f a #
type Rep (Free f a) # |
type Rep (Free f a) = D1 (MetaData "Free" "Control.Monad.Free" "control-monad-free-0.6.1-6sHLlBhFKrC1QUKEf8Gbv7" False) ((:+:) (C1 (MetaCons "Impure" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (f (Free f a))))) (C1 (MetaCons "Pure" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a))))

isPure :: Free t1 t -> Bool #

isImpure :: Free t1 t -> Bool #

foldFree :: Functor f => (a -> b) -> (f b -> b) -> Free f a -> b #

evalFree :: (a -> b) -> (f (Free f a) -> b) -> Free f a -> b #

mapFree :: (Functor f, Functor g) => (f (Free g a) -> g (Free g a)) -> Free f a -> Free g a #

mapFreeM :: (Traversable f, Functor g, Monad m) => (f (Free g a) -> m (g (Free g a))) -> Free f a -> m (Free g a) #

mapFreeM' :: (Functor f, Traversable g, Monad m) => (forall a. f a -> m (g a)) -> Free f a -> m (Free g a) #

# Monad Morphisms

foldFreeM :: (Traversable f, Monad m) => (a -> m b) -> (f b -> m b) -> Free f a -> m b #

induce :: (Functor f, Monad m) => (forall a. f a -> m a) -> Free f a -> m a #

# Free Monad Transformers

newtype FreeT f m a #

Constructors

FreeT |
Fields unFreeT :: m (Either a (f (FreeT f m a)))

Instances

(Monad m, Functor f) => MonadFree f (C (FreeT f m)) # |
Methods free :: C (FreeT f m) a -> C (FreeT f m) (Either a (f (C (FreeT f m) a))) # wrap :: f (C (FreeT f m) a) -> C (FreeT f m) a #
(Functor f, Monad m) => MonadFree f (FreeT f m) # |
Methods free :: FreeT f m a -> FreeT f m (Either a (f (FreeT f m a))) # wrap :: f (FreeT f m a) -> FreeT f m a #
Functor f => MonadTrans (FreeT f) # |
Methods lift :: Monad m => m a -> FreeT f m a #
(Functor f, Monad m) => Monad (FreeT f m) # |
Methods (>>=) :: FreeT f m a -> (a -> FreeT f m b) -> FreeT f m b # (>>) :: FreeT f m a -> FreeT f m b -> FreeT f m b # return :: a -> FreeT f m a # fail :: String -> FreeT f m a #
(Functor f, Functor m) => Functor (FreeT f m) # |
Methods fmap :: (a -> b) -> FreeT f m a -> FreeT f m b # (<$) :: a -> FreeT f m b -> FreeT f m a #
(Functor f, Functor a, Monad a) => Applicative (FreeT f a) # |
Methods pure :: a -> FreeT f a a # (<*>) :: FreeT f a (a -> b) -> FreeT f a a -> FreeT f a b # (*>) :: FreeT f a a -> FreeT f a b -> FreeT f a b # (<*) :: FreeT f a a -> FreeT f a b -> FreeT f a a #
(Traversable m, Traversable f) => Foldable (FreeT f m) # |
Methods fold :: Monoid m => FreeT f m m -> m # foldMap :: Monoid m => (a -> m) -> FreeT f m a -> m # foldr :: (a -> b -> b) -> b -> FreeT f m a -> b # foldr' :: (a -> b -> b) -> b -> FreeT f m a -> b # foldl :: (b -> a -> b) -> b -> FreeT f m a -> b # foldl' :: (b -> a -> b) -> b -> FreeT f m a -> b # foldr1 :: (a -> a -> a) -> FreeT f m a -> a # foldl1 :: (a -> a -> a) -> FreeT f m a -> a # toList :: FreeT f m a -> [a] # null :: FreeT f m a -> Bool # length :: FreeT f m a -> Int # elem :: Eq a => a -> FreeT f m a -> Bool # maximum :: Ord a => FreeT f m a -> a # minimum :: Ord a => FreeT f m a -> a # sum :: Num a => FreeT f m a -> a # product :: Num a => FreeT f m a -> a #
(Traversable m, Traversable f) => Traversable (FreeT f m) # |
Methods traverse :: Applicative f => (a -> f b) -> FreeT f m a -> f (FreeT f m b) # sequenceA :: Applicative f => FreeT f m (f a) -> f (FreeT f m a) # mapM :: Monad m => (a -> m b) -> FreeT f m a -> m (FreeT f m b) # sequence :: Monad m => FreeT f m (m a) -> m (FreeT f m a) #
(Functor f, Monad m, MonadIO m) => MonadIO (FreeT f m) # |
Methods liftIO :: IO a -> FreeT f m a #
(Functor f, Functor m, Monad m, MonadPlus m) => Alternative (FreeT f m) # |
Methods empty :: FreeT f m a # (<|>) :: FreeT f m a -> FreeT f m a -> FreeT f m a # some :: FreeT f m a -> FreeT f m [a] # many :: FreeT f m a -> FreeT f m [a] #
(Functor f, Monad m, MonadPlus m) => MonadPlus (FreeT f m) # |
Methods mzero :: FreeT f m a # mplus :: FreeT f m a -> FreeT f m a -> FreeT f m a #

foldFreeT :: (Traversable f, Monad m) => (a -> m b) -> (f b -> m b) -> FreeT f m a -> m b #

foldFreeT' :: (Traversable f, Monad m) => (a -> b) -> (f b -> b) -> FreeT f m a -> m b #

mapFreeT :: (Functor f, Functor m) => (forall a. m a -> m' a) -> FreeT f m a -> FreeT f m' a #

foldFreeA :: (Traversable f, Applicative m) => (a -> m b) -> m (f b -> b) -> Free f a -> m b #

mapFreeA :: (Traversable f, Functor g, Applicative m) => m (f (Free g a) -> g (Free g a)) -> Free f a -> m (Free g a) #

# Translate between Free monad and Free monad transformer computations

trans :: MonadFree f m => Free f a -> m a #

trans' :: (Functor f, Monad m) => m (Free f a) -> FreeT f m a #

untrans :: (Traversable f, Monad m) => FreeT f m a -> m (Free f a) #

liftFree :: (Functor f, Monad m) => (a -> Free f b) -> a -> FreeT f m b #