{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}

-- | Another way to make 'FreeT' an instance of 'FMonad'
-- 
-- 'FreeT' can be 'FMonad' in two different ways. There is already an instance:
-- 
-- @
-- instance Functor f => FMonad (FreeT f) where
--   fpure :: Functor m => m ~> FreeT f m
--   fbind :: (Functor m, Functor n) => (m ~> FreeT f n) -> (FreeT f m ~> FreeT f n)
-- @
-- 
-- In addition to this standard instance, @FreeT f m@ have @FMonad@-like structure by treating
-- @f@ as the parameter while fixing @m@ to some arbitrary @Monad@.
-- 
-- @
-- 'fpureFst' :: (Monad m) => (Functor f) => f ~> FreeT f m
-- 'fbindFst' :: (Monad m) => (Functor f, Functor g) => (f ~> FreeT g m) -> (FreeT f m ~> FreeT g m)
-- @
-- 
-- This module provides a newtype wrapper 'FreeT'' to use these as a real @FMonad@
-- instance.
module FMonad.FreeT
  ( FreeT' (..), liftM', fpureFst, fbindFst )
where

import Control.Applicative (Alternative)
import Control.Monad (MonadPlus)
import Control.Monad.Trans.Free
import Control.Monad.Trans.Free.Extra
import Data.Functor.Classes
import FMonad

-- | @FreeT'@ is a @FreeT@, but with the order of its arguments flipped.
--
-- @
-- FreeT' m f a ≡ FreeT f m a
-- @
newtype FreeT' m f b = WrapFreeT' {forall (m :: * -> *) (f :: * -> *) b. FreeT' m f b -> FreeT f m b
unwrapFreeT' :: FreeT f m b}
  deriving
    ((forall a b. (a -> b) -> FreeT' m f a -> FreeT' m f b)
-> (forall a b. a -> FreeT' m f b -> FreeT' m f a)
-> Functor (FreeT' m f)
forall a b. a -> FreeT' m f b -> FreeT' m f a
forall a b. (a -> b) -> FreeT' m f a -> FreeT' m f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (f :: * -> *) (m :: * -> *) a b.
(Functor f, Functor m) =>
a -> FreeT' m f b -> FreeT' m f a
forall (f :: * -> *) (m :: * -> *) a b.
(Functor f, Functor m) =>
(a -> b) -> FreeT' m f a -> FreeT' m f b
$cfmap :: forall (f :: * -> *) (m :: * -> *) a b.
(Functor f, Functor m) =>
(a -> b) -> FreeT' m f a -> FreeT' m f b
fmap :: forall a b. (a -> b) -> FreeT' m f a -> FreeT' m f b
$c<$ :: forall (f :: * -> *) (m :: * -> *) a b.
(Functor f, Functor m) =>
a -> FreeT' m f b -> FreeT' m f a
<$ :: forall a b. a -> FreeT' m f b -> FreeT' m f a
Functor)
    via (FreeT f m)
  deriving
    ( Functor (FreeT' m f)
Functor (FreeT' m f) =>
(forall a. a -> FreeT' m f a)
-> (forall a b.
    FreeT' m f (a -> b) -> FreeT' m f a -> FreeT' m f b)
-> (forall a b c.
    (a -> b -> c) -> FreeT' m f a -> FreeT' m f b -> FreeT' m f c)
-> (forall a b. FreeT' m f a -> FreeT' m f b -> FreeT' m f b)
-> (forall a b. FreeT' m f a -> FreeT' m f b -> FreeT' m f a)
-> Applicative (FreeT' m f)
forall a. a -> FreeT' m f a
forall a b. FreeT' m f a -> FreeT' m f b -> FreeT' m f a
forall a b. FreeT' m f a -> FreeT' m f b -> FreeT' m f b
forall a b. FreeT' m f (a -> b) -> FreeT' m f a -> FreeT' m f b
forall a b c.
(a -> b -> c) -> FreeT' m f a -> FreeT' m f b -> FreeT' m f c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (f :: * -> *) (m :: * -> *).
(Monad m, Functor f) =>
Functor (FreeT' m f)
forall (f :: * -> *) (m :: * -> *) a.
(Monad m, Functor f) =>
a -> FreeT' m f a
forall (f :: * -> *) (m :: * -> *) a b.
(Monad m, Functor f) =>
FreeT' m f a -> FreeT' m f b -> FreeT' m f a
forall (f :: * -> *) (m :: * -> *) a b.
(Monad m, Functor f) =>
FreeT' m f a -> FreeT' m f b -> FreeT' m f b
forall (f :: * -> *) (m :: * -> *) a b.
(Monad m, Functor f) =>
FreeT' m f (a -> b) -> FreeT' m f a -> FreeT' m f b
forall (f :: * -> *) (m :: * -> *) a b c.
(Monad m, Functor f) =>
(a -> b -> c) -> FreeT' m f a -> FreeT' m f b -> FreeT' m f c
$cpure :: forall (f :: * -> *) (m :: * -> *) a.
(Monad m, Functor f) =>
a -> FreeT' m f a
pure :: forall a. a -> FreeT' m f a
$c<*> :: forall (f :: * -> *) (m :: * -> *) a b.
(Monad m, Functor f) =>
FreeT' m f (a -> b) -> FreeT' m f a -> FreeT' m f b
<*> :: forall a b. FreeT' m f (a -> b) -> FreeT' m f a -> FreeT' m f b
$cliftA2 :: forall (f :: * -> *) (m :: * -> *) a b c.
(Monad m, Functor f) =>
(a -> b -> c) -> FreeT' m f a -> FreeT' m f b -> FreeT' m f c
liftA2 :: forall a b c.
(a -> b -> c) -> FreeT' m f a -> FreeT' m f b -> FreeT' m f c
$c*> :: forall (f :: * -> *) (m :: * -> *) a b.
(Monad m, Functor f) =>
FreeT' m f a -> FreeT' m f b -> FreeT' m f b
*> :: forall a b. FreeT' m f a -> FreeT' m f b -> FreeT' m f b
$c<* :: forall (f :: * -> *) (m :: * -> *) a b.
(Monad m, Functor f) =>
FreeT' m f a -> FreeT' m f b -> FreeT' m f a
<* :: forall a b. FreeT' m f a -> FreeT' m f b -> FreeT' m f a
Applicative,
      Applicative (FreeT' m f)
Applicative (FreeT' m f) =>
(forall a. FreeT' m f a)
-> (forall a. FreeT' m f a -> FreeT' m f a -> FreeT' m f a)
-> (forall a. FreeT' m f a -> FreeT' m f [a])
-> (forall a. FreeT' m f a -> FreeT' m f [a])
-> Alternative (FreeT' m f)
forall a. FreeT' m f a
forall a. FreeT' m f a -> FreeT' m f [a]
forall a. FreeT' m f a -> FreeT' m f a -> FreeT' m f a
forall (f :: * -> *).
Applicative f =>
(forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall (f :: * -> *) (m :: * -> *).
(MonadPlus m, Functor f) =>
Applicative (FreeT' m f)
forall (f :: * -> *) (m :: * -> *) a.
(MonadPlus m, Functor f) =>
FreeT' m f a
forall (f :: * -> *) (m :: * -> *) a.
(MonadPlus m, Functor f) =>
FreeT' m f a -> FreeT' m f [a]
forall (f :: * -> *) (m :: * -> *) a.
(MonadPlus m, Functor f) =>
FreeT' m f a -> FreeT' m f a -> FreeT' m f a
$cempty :: forall (f :: * -> *) (m :: * -> *) a.
(MonadPlus m, Functor f) =>
FreeT' m f a
empty :: forall a. FreeT' m f a
$c<|> :: forall (f :: * -> *) (m :: * -> *) a.
(MonadPlus m, Functor f) =>
FreeT' m f a -> FreeT' m f a -> FreeT' m f a
<|> :: forall a. FreeT' m f a -> FreeT' m f a -> FreeT' m f a
$csome :: forall (f :: * -> *) (m :: * -> *) a.
(MonadPlus m, Functor f) =>
FreeT' m f a -> FreeT' m f [a]
some :: forall a. FreeT' m f a -> FreeT' m f [a]
$cmany :: forall (f :: * -> *) (m :: * -> *) a.
(MonadPlus m, Functor f) =>
FreeT' m f a -> FreeT' m f [a]
many :: forall a. FreeT' m f a -> FreeT' m f [a]
Alternative,
      Applicative (FreeT' m f)
Applicative (FreeT' m f) =>
(forall a b. FreeT' m f a -> (a -> FreeT' m f b) -> FreeT' m f b)
-> (forall a b. FreeT' m f a -> FreeT' m f b -> FreeT' m f b)
-> (forall a. a -> FreeT' m f a)
-> Monad (FreeT' m f)
forall a. a -> FreeT' m f a
forall a b. FreeT' m f a -> FreeT' m f b -> FreeT' m f b
forall a b. FreeT' m f a -> (a -> FreeT' m f b) -> FreeT' m f b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
forall (f :: * -> *) (m :: * -> *).
(Monad m, Functor f) =>
Applicative (FreeT' m f)
forall (f :: * -> *) (m :: * -> *) a.
(Monad m, Functor f) =>
a -> FreeT' m f a
forall (f :: * -> *) (m :: * -> *) a b.
(Monad m, Functor f) =>
FreeT' m f a -> FreeT' m f b -> FreeT' m f b
forall (f :: * -> *) (m :: * -> *) a b.
(Monad m, Functor f) =>
FreeT' m f a -> (a -> FreeT' m f b) -> FreeT' m f b
$c>>= :: forall (f :: * -> *) (m :: * -> *) a b.
(Monad m, Functor f) =>
FreeT' m f a -> (a -> FreeT' m f b) -> FreeT' m f b
>>= :: forall a b. FreeT' m f a -> (a -> FreeT' m f b) -> FreeT' m f b
$c>> :: forall (f :: * -> *) (m :: * -> *) a b.
(Monad m, Functor f) =>
FreeT' m f a -> FreeT' m f b -> FreeT' m f b
>> :: forall a b. FreeT' m f a -> FreeT' m f b -> FreeT' m f b
$creturn :: forall (f :: * -> *) (m :: * -> *) a.
(Monad m, Functor f) =>
a -> FreeT' m f a
return :: forall a. a -> FreeT' m f a
Monad,
      Monad (FreeT' m f)
Alternative (FreeT' m f)
(Alternative (FreeT' m f), Monad (FreeT' m f)) =>
(forall a. FreeT' m f a)
-> (forall a. FreeT' m f a -> FreeT' m f a -> FreeT' m f a)
-> MonadPlus (FreeT' m f)
forall a. FreeT' m f a
forall a. FreeT' m f a -> FreeT' m f a -> FreeT' m f a
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
forall (f :: * -> *) (m :: * -> *).
(MonadPlus m, Functor f) =>
Monad (FreeT' m f)
forall (f :: * -> *) (m :: * -> *).
(MonadPlus m, Functor f) =>
Alternative (FreeT' m f)
forall (f :: * -> *) (m :: * -> *) a.
(MonadPlus m, Functor f) =>
FreeT' m f a
forall (f :: * -> *) (m :: * -> *) a.
(MonadPlus m, Functor f) =>
FreeT' m f a -> FreeT' m f a -> FreeT' m f a
$cmzero :: forall (f :: * -> *) (m :: * -> *) a.
(MonadPlus m, Functor f) =>
FreeT' m f a
mzero :: forall a. FreeT' m f a
$cmplus :: forall (f :: * -> *) (m :: * -> *) a.
(MonadPlus m, Functor f) =>
FreeT' m f a -> FreeT' m f a -> FreeT' m f a
mplus :: forall a. FreeT' m f a -> FreeT' m f a -> FreeT' m f a
MonadPlus,
      (forall m. Monoid m => FreeT' m f m -> m)
-> (forall m a. Monoid m => (a -> m) -> FreeT' m f a -> m)
-> (forall m a. Monoid m => (a -> m) -> FreeT' m f a -> m)
-> (forall a b. (a -> b -> b) -> b -> FreeT' m f a -> b)
-> (forall a b. (a -> b -> b) -> b -> FreeT' m f a -> b)
-> (forall b a. (b -> a -> b) -> b -> FreeT' m f a -> b)
-> (forall b a. (b -> a -> b) -> b -> FreeT' m f a -> b)
-> (forall a. (a -> a -> a) -> FreeT' m f a -> a)
-> (forall a. (a -> a -> a) -> FreeT' m f a -> a)
-> (forall a. FreeT' m f a -> [a])
-> (forall a. FreeT' m f a -> Bool)
-> (forall a. FreeT' m f a -> Int)
-> (forall a. Eq a => a -> FreeT' m f a -> Bool)
-> (forall a. Ord a => FreeT' m f a -> a)
-> (forall a. Ord a => FreeT' m f a -> a)
-> (forall a. Num a => FreeT' m f a -> a)
-> (forall a. Num a => FreeT' m f a -> a)
-> Foldable (FreeT' m f)
forall a. Eq a => a -> FreeT' m f a -> Bool
forall a. Num a => FreeT' m f a -> a
forall a. Ord a => FreeT' m f a -> a
forall m. Monoid m => FreeT' m f m -> m
forall a. FreeT' m f a -> Bool
forall a. FreeT' m f a -> Int
forall a. FreeT' m f a -> [a]
forall a. (a -> a -> a) -> FreeT' m f a -> a
forall m a. Monoid m => (a -> m) -> FreeT' m f a -> m
forall b a. (b -> a -> b) -> b -> FreeT' m f a -> b
forall a b. (a -> b -> b) -> b -> FreeT' m f a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f, Eq a) =>
a -> FreeT' m f a -> Bool
forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f, Num a) =>
FreeT' m f a -> a
forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f, Ord a) =>
FreeT' m f a -> a
forall (f :: * -> *) (m :: * -> *) m.
(Foldable m, Foldable f, Monoid m) =>
FreeT' m f m -> m
forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f) =>
FreeT' m f a -> Bool
forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f) =>
FreeT' m f a -> Int
forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f) =>
FreeT' m f a -> [a]
forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f) =>
(a -> a -> a) -> FreeT' m f a -> a
forall (f :: * -> *) (m :: * -> *) m a.
(Foldable m, Foldable f, Monoid m) =>
(a -> m) -> FreeT' m f a -> m
forall (f :: * -> *) (m :: * -> *) b a.
(Foldable m, Foldable f) =>
(b -> a -> b) -> b -> FreeT' m f a -> b
forall (f :: * -> *) (m :: * -> *) a b.
(Foldable m, Foldable f) =>
(a -> b -> b) -> b -> FreeT' m f a -> b
$cfold :: forall (f :: * -> *) (m :: * -> *) m.
(Foldable m, Foldable f, Monoid m) =>
FreeT' m f m -> m
fold :: forall m. Monoid m => FreeT' m f m -> m
$cfoldMap :: forall (f :: * -> *) (m :: * -> *) m a.
(Foldable m, Foldable f, Monoid m) =>
(a -> m) -> FreeT' m f a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> FreeT' m f a -> m
$cfoldMap' :: forall (f :: * -> *) (m :: * -> *) m a.
(Foldable m, Foldable f, Monoid m) =>
(a -> m) -> FreeT' m f a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> FreeT' m f a -> m
$cfoldr :: forall (f :: * -> *) (m :: * -> *) a b.
(Foldable m, Foldable f) =>
(a -> b -> b) -> b -> FreeT' m f a -> b
foldr :: forall a b. (a -> b -> b) -> b -> FreeT' m f a -> b
$cfoldr' :: forall (f :: * -> *) (m :: * -> *) a b.
(Foldable m, Foldable f) =>
(a -> b -> b) -> b -> FreeT' m f a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> FreeT' m f a -> b
$cfoldl :: forall (f :: * -> *) (m :: * -> *) b a.
(Foldable m, Foldable f) =>
(b -> a -> b) -> b -> FreeT' m f a -> b
foldl :: forall b a. (b -> a -> b) -> b -> FreeT' m f a -> b
$cfoldl' :: forall (f :: * -> *) (m :: * -> *) b a.
(Foldable m, Foldable f) =>
(b -> a -> b) -> b -> FreeT' m f a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> FreeT' m f a -> b
$cfoldr1 :: forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f) =>
(a -> a -> a) -> FreeT' m f a -> a
foldr1 :: forall a. (a -> a -> a) -> FreeT' m f a -> a
$cfoldl1 :: forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f) =>
(a -> a -> a) -> FreeT' m f a -> a
foldl1 :: forall a. (a -> a -> a) -> FreeT' m f a -> a
$ctoList :: forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f) =>
FreeT' m f a -> [a]
toList :: forall a. FreeT' m f a -> [a]
$cnull :: forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f) =>
FreeT' m f a -> Bool
null :: forall a. FreeT' m f a -> Bool
$clength :: forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f) =>
FreeT' m f a -> Int
length :: forall a. FreeT' m f a -> Int
$celem :: forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f, Eq a) =>
a -> FreeT' m f a -> Bool
elem :: forall a. Eq a => a -> FreeT' m f a -> Bool
$cmaximum :: forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f, Ord a) =>
FreeT' m f a -> a
maximum :: forall a. Ord a => FreeT' m f a -> a
$cminimum :: forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f, Ord a) =>
FreeT' m f a -> a
minimum :: forall a. Ord a => FreeT' m f a -> a
$csum :: forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f, Num a) =>
FreeT' m f a -> a
sum :: forall a. Num a => FreeT' m f a -> a
$cproduct :: forall (f :: * -> *) (m :: * -> *) a.
(Foldable m, Foldable f, Num a) =>
FreeT' m f a -> a
product :: forall a. Num a => FreeT' m f a -> a
Foldable,
      (forall a. Eq a => Eq (FreeT' m f a)) =>
(forall a b.
 (a -> b -> Bool) -> FreeT' m f a -> FreeT' m f b -> Bool)
-> Eq1 (FreeT' m f)
forall a. Eq a => Eq (FreeT' m f a)
forall a b.
(a -> b -> Bool) -> FreeT' m f a -> FreeT' m f b -> Bool
forall (f :: * -> *).
(forall a. Eq a => Eq (f a)) =>
(forall a b. (a -> b -> Bool) -> f a -> f b -> Bool) -> Eq1 f
forall (f :: * -> *) (m :: * -> *) a.
(Eq1 f, Eq1 m, Eq a) =>
Eq (FreeT' m f a)
forall (f :: * -> *) (m :: * -> *) a b.
(Eq1 f, Eq1 m) =>
(a -> b -> Bool) -> FreeT' m f a -> FreeT' m f b -> Bool
$cliftEq :: forall (f :: * -> *) (m :: * -> *) a b.
(Eq1 f, Eq1 m) =>
(a -> b -> Bool) -> FreeT' m f a -> FreeT' m f b -> Bool
liftEq :: forall a b.
(a -> b -> Bool) -> FreeT' m f a -> FreeT' m f b -> Bool
Eq1,
      Eq1 (FreeT' m f)
(Eq1 (FreeT' m f), forall a. Ord a => Ord (FreeT' m f a)) =>
(forall a b.
 (a -> b -> Ordering) -> FreeT' m f a -> FreeT' m f b -> Ordering)
-> Ord1 (FreeT' m f)
forall a. Ord a => Ord (FreeT' m f a)
forall a b.
(a -> b -> Ordering) -> FreeT' m f a -> FreeT' m f b -> Ordering
forall (f :: * -> *).
(Eq1 f, forall a. Ord a => Ord (f a)) =>
(forall a b. (a -> b -> Ordering) -> f a -> f b -> Ordering)
-> Ord1 f
forall (f :: * -> *) (m :: * -> *).
(Ord1 f, Ord1 m) =>
Eq1 (FreeT' m f)
forall (f :: * -> *) (m :: * -> *) a.
(Ord1 f, Ord1 m, Ord a) =>
Ord (FreeT' m f a)
forall (f :: * -> *) (m :: * -> *) a b.
(Ord1 f, Ord1 m) =>
(a -> b -> Ordering) -> FreeT' m f a -> FreeT' m f b -> Ordering
$cliftCompare :: forall (f :: * -> *) (m :: * -> *) a b.
(Ord1 f, Ord1 m) =>
(a -> b -> Ordering) -> FreeT' m f a -> FreeT' m f b -> Ordering
liftCompare :: forall a b.
(a -> b -> Ordering) -> FreeT' m f a -> FreeT' m f b -> Ordering
Ord1,
      (forall a. Show a => Show (FreeT' m f a)) =>
(forall a.
 (Int -> a -> ShowS)
 -> ([a] -> ShowS) -> Int -> FreeT' m f a -> ShowS)
-> (forall a.
    (Int -> a -> ShowS) -> ([a] -> ShowS) -> [FreeT' m f a] -> ShowS)
-> Show1 (FreeT' m f)
forall a. Show a => Show (FreeT' m f a)
forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> FreeT' m f a -> ShowS
forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [FreeT' m f a] -> ShowS
forall (f :: * -> *).
(forall a. Show a => Show (f a)) =>
(forall a.
 (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS)
-> (forall a.
    (Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS)
-> Show1 f
forall (f :: * -> *) (m :: * -> *) a.
(Show1 f, Show1 m, Show a) =>
Show (FreeT' m f a)
forall (f :: * -> *) (m :: * -> *) a.
(Show1 f, Show1 m) =>
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> FreeT' m f a -> ShowS
forall (f :: * -> *) (m :: * -> *) a.
(Show1 f, Show1 m) =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [FreeT' m f a] -> ShowS
$cliftShowsPrec :: forall (f :: * -> *) (m :: * -> *) a.
(Show1 f, Show1 m) =>
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> FreeT' m f a -> ShowS
liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> FreeT' m f a -> ShowS
$cliftShowList :: forall (f :: * -> *) (m :: * -> *) a.
(Show1 f, Show1 m) =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [FreeT' m f a] -> ShowS
liftShowList :: forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [FreeT' m f a] -> ShowS
Show1,
      (forall a. Read a => Read (FreeT' m f a)) =>
(forall a.
 (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (FreeT' m f a))
-> (forall a.
    (Int -> ReadS a) -> ReadS [a] -> ReadS [FreeT' m f a])
-> (forall a.
    ReadPrec a -> ReadPrec [a] -> ReadPrec (FreeT' m f a))
-> (forall a.
    ReadPrec a -> ReadPrec [a] -> ReadPrec [FreeT' m f a])
-> Read1 (FreeT' m f)
forall a. Read a => Read (FreeT' m f a)
forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec [FreeT' m f a]
forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec (FreeT' m f a)
forall a.
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (FreeT' m f a)
forall a. (Int -> ReadS a) -> ReadS [a] -> ReadS [FreeT' m f a]
forall (f :: * -> *).
(forall a. Read a => Read (f a)) =>
(forall a. (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a))
-> (forall a. (Int -> ReadS a) -> ReadS [a] -> ReadS [f a])
-> (forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec (f a))
-> (forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec [f a])
-> Read1 f
forall (f :: * -> *) (m :: * -> *) a.
(Read1 f, Read1 m, Read a) =>
Read (FreeT' m f a)
forall (f :: * -> *) (m :: * -> *) a.
(Read1 f, Read1 m) =>
ReadPrec a -> ReadPrec [a] -> ReadPrec [FreeT' m f a]
forall (f :: * -> *) (m :: * -> *) a.
(Read1 f, Read1 m) =>
ReadPrec a -> ReadPrec [a] -> ReadPrec (FreeT' m f a)
forall (f :: * -> *) (m :: * -> *) a.
(Read1 f, Read1 m) =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (FreeT' m f a)
forall (f :: * -> *) (m :: * -> *) a.
(Read1 f, Read1 m) =>
(Int -> ReadS a) -> ReadS [a] -> ReadS [FreeT' m f a]
$cliftReadsPrec :: forall (f :: * -> *) (m :: * -> *) a.
(Read1 f, Read1 m) =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (FreeT' m f a)
liftReadsPrec :: forall a.
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (FreeT' m f a)
$cliftReadList :: forall (f :: * -> *) (m :: * -> *) a.
(Read1 f, Read1 m) =>
(Int -> ReadS a) -> ReadS [a] -> ReadS [FreeT' m f a]
liftReadList :: forall a. (Int -> ReadS a) -> ReadS [a] -> ReadS [FreeT' m f a]
$cliftReadPrec :: forall (f :: * -> *) (m :: * -> *) a.
(Read1 f, Read1 m) =>
ReadPrec a -> ReadPrec [a] -> ReadPrec (FreeT' m f a)
liftReadPrec :: forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec (FreeT' m f a)
$cliftReadListPrec :: forall (f :: * -> *) (m :: * -> *) a.
(Read1 f, Read1 m) =>
ReadPrec a -> ReadPrec [a] -> ReadPrec [FreeT' m f a]
liftReadListPrec :: forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec [FreeT' m f a]
Read1
    )
    via (FreeT f m)
  deriving
    (Int -> FreeT' m f b -> ShowS
[FreeT' m f b] -> ShowS
FreeT' m f b -> String
(Int -> FreeT' m f b -> ShowS)
-> (FreeT' m f b -> String)
-> ([FreeT' m f b] -> ShowS)
-> Show (FreeT' m f b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (f :: * -> *) (m :: * -> *) b.
(Show1 f, Show1 m, Show b) =>
Int -> FreeT' m f b -> ShowS
forall (f :: * -> *) (m :: * -> *) b.
(Show1 f, Show1 m, Show b) =>
[FreeT' m f b] -> ShowS
forall (f :: * -> *) (m :: * -> *) b.
(Show1 f, Show1 m, Show b) =>
FreeT' m f b -> String
$cshowsPrec :: forall (f :: * -> *) (m :: * -> *) b.
(Show1 f, Show1 m, Show b) =>
Int -> FreeT' m f b -> ShowS
showsPrec :: Int -> FreeT' m f b -> ShowS
$cshow :: forall (f :: * -> *) (m :: * -> *) b.
(Show1 f, Show1 m, Show b) =>
FreeT' m f b -> String
show :: FreeT' m f b -> String
$cshowList :: forall (f :: * -> *) (m :: * -> *) b.
(Show1 f, Show1 m, Show b) =>
[FreeT' m f b] -> ShowS
showList :: [FreeT' m f b] -> ShowS
Show, ReadPrec [FreeT' m f b]
ReadPrec (FreeT' m f b)
Int -> ReadS (FreeT' m f b)
ReadS [FreeT' m f b]
(Int -> ReadS (FreeT' m f b))
-> ReadS [FreeT' m f b]
-> ReadPrec (FreeT' m f b)
-> ReadPrec [FreeT' m f b]
-> Read (FreeT' m f b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall (f :: * -> *) (m :: * -> *) b.
(Read1 f, Read1 m, Read b) =>
ReadPrec [FreeT' m f b]
forall (f :: * -> *) (m :: * -> *) b.
(Read1 f, Read1 m, Read b) =>
ReadPrec (FreeT' m f b)
forall (f :: * -> *) (m :: * -> *) b.
(Read1 f, Read1 m, Read b) =>
Int -> ReadS (FreeT' m f b)
forall (f :: * -> *) (m :: * -> *) b.
(Read1 f, Read1 m, Read b) =>
ReadS [FreeT' m f b]
$creadsPrec :: forall (f :: * -> *) (m :: * -> *) b.
(Read1 f, Read1 m, Read b) =>
Int -> ReadS (FreeT' m f b)
readsPrec :: Int -> ReadS (FreeT' m f b)
$creadList :: forall (f :: * -> *) (m :: * -> *) b.
(Read1 f, Read1 m, Read b) =>
ReadS [FreeT' m f b]
readList :: ReadS [FreeT' m f b]
$creadPrec :: forall (f :: * -> *) (m :: * -> *) b.
(Read1 f, Read1 m, Read b) =>
ReadPrec (FreeT' m f b)
readPrec :: ReadPrec (FreeT' m f b)
$creadListPrec :: forall (f :: * -> *) (m :: * -> *) b.
(Read1 f, Read1 m, Read b) =>
ReadPrec [FreeT' m f b]
readListPrec :: ReadPrec [FreeT' m f b]
Read, FreeT' m f b -> FreeT' m f b -> Bool
(FreeT' m f b -> FreeT' m f b -> Bool)
-> (FreeT' m f b -> FreeT' m f b -> Bool) -> Eq (FreeT' m f b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (f :: * -> *) (m :: * -> *) b.
(Eq1 f, Eq1 m, Eq b) =>
FreeT' m f b -> FreeT' m f b -> Bool
$c== :: forall (f :: * -> *) (m :: * -> *) b.
(Eq1 f, Eq1 m, Eq b) =>
FreeT' m f b -> FreeT' m f b -> Bool
== :: FreeT' m f b -> FreeT' m f b -> Bool
$c/= :: forall (f :: * -> *) (m :: * -> *) b.
(Eq1 f, Eq1 m, Eq b) =>
FreeT' m f b -> FreeT' m f b -> Bool
/= :: FreeT' m f b -> FreeT' m f b -> Bool
Eq, Eq (FreeT' m f b)
Eq (FreeT' m f b) =>
(FreeT' m f b -> FreeT' m f b -> Ordering)
-> (FreeT' m f b -> FreeT' m f b -> Bool)
-> (FreeT' m f b -> FreeT' m f b -> Bool)
-> (FreeT' m f b -> FreeT' m f b -> Bool)
-> (FreeT' m f b -> FreeT' m f b -> Bool)
-> (FreeT' m f b -> FreeT' m f b -> FreeT' m f b)
-> (FreeT' m f b -> FreeT' m f b -> FreeT' m f b)
-> Ord (FreeT' m f b)
FreeT' m f b -> FreeT' m f b -> Bool
FreeT' m f b -> FreeT' m f b -> Ordering
FreeT' m f b -> FreeT' m f b -> FreeT' m f b
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall (f :: * -> *) (m :: * -> *) b.
(Ord1 f, Ord1 m, Ord b) =>
Eq (FreeT' m f b)
forall (f :: * -> *) (m :: * -> *) b.
(Ord1 f, Ord1 m, Ord b) =>
FreeT' m f b -> FreeT' m f b -> Bool
forall (f :: * -> *) (m :: * -> *) b.
(Ord1 f, Ord1 m, Ord b) =>
FreeT' m f b -> FreeT' m f b -> Ordering
forall (f :: * -> *) (m :: * -> *) b.
(Ord1 f, Ord1 m, Ord b) =>
FreeT' m f b -> FreeT' m f b -> FreeT' m f b
$ccompare :: forall (f :: * -> *) (m :: * -> *) b.
(Ord1 f, Ord1 m, Ord b) =>
FreeT' m f b -> FreeT' m f b -> Ordering
compare :: FreeT' m f b -> FreeT' m f b -> Ordering
$c< :: forall (f :: * -> *) (m :: * -> *) b.
(Ord1 f, Ord1 m, Ord b) =>
FreeT' m f b -> FreeT' m f b -> Bool
< :: FreeT' m f b -> FreeT' m f b -> Bool
$c<= :: forall (f :: * -> *) (m :: * -> *) b.
(Ord1 f, Ord1 m, Ord b) =>
FreeT' m f b -> FreeT' m f b -> Bool
<= :: FreeT' m f b -> FreeT' m f b -> Bool
$c> :: forall (f :: * -> *) (m :: * -> *) b.
(Ord1 f, Ord1 m, Ord b) =>
FreeT' m f b -> FreeT' m f b -> Bool
> :: FreeT' m f b -> FreeT' m f b -> Bool
$c>= :: forall (f :: * -> *) (m :: * -> *) b.
(Ord1 f, Ord1 m, Ord b) =>
FreeT' m f b -> FreeT' m f b -> Bool
>= :: FreeT' m f b -> FreeT' m f b -> Bool
$cmax :: forall (f :: * -> *) (m :: * -> *) b.
(Ord1 f, Ord1 m, Ord b) =>
FreeT' m f b -> FreeT' m f b -> FreeT' m f b
max :: FreeT' m f b -> FreeT' m f b -> FreeT' m f b
$cmin :: forall (f :: * -> *) (m :: * -> *) b.
(Ord1 f, Ord1 m, Ord b) =>
FreeT' m f b -> FreeT' m f b -> FreeT' m f b
min :: FreeT' m f b -> FreeT' m f b -> FreeT' m f b
Ord)
    via (FreeT f m b)

-- | Lift of the Monad side.
liftM' :: Functor m => m a -> FreeT' m f a
liftM' :: forall (m :: * -> *) a (f :: * -> *).
Functor m =>
m a -> FreeT' m f a
liftM' = FreeT f m a -> FreeT' m f a
forall (m :: * -> *) (f :: * -> *) b. FreeT f m b -> FreeT' m f b
WrapFreeT' (FreeT f m a -> FreeT' m f a)
-> (m a -> FreeT f m a) -> m a -> FreeT' m f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> FreeT f m a
m ~> FreeT f m
forall (m :: * -> *) (f :: * -> *). Functor m => m ~> FreeT f m
inr

-- | @fpure@ to the first parameter of @FreeT@
fpureFst :: (Monad m) => (Functor f) => f ~> FreeT f m
fpureFst :: forall (m :: * -> *) (f :: * -> *).
(Monad m, Functor f) =>
f ~> FreeT f m
fpureFst = f x -> FreeT f m x
forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF

-- | @fbind@ to the first parameter of @FreeT@
fbindFst :: (Monad m) => (Functor f, Functor g) => (f ~> FreeT g m) -> (FreeT f m ~> FreeT g m)
fbindFst :: forall (m :: * -> *) (f :: * -> *) (g :: * -> *).
(Monad m, Functor f, Functor g) =>
(f ~> FreeT g m) -> FreeT f m ~> FreeT g m
fbindFst f ~> FreeT g m
k = (f ~> FreeT g m) -> (m ~> FreeT g m) -> FreeT f m ~> FreeT g m
forall (n :: * -> *) (f :: * -> *) (m :: * -> *).
Monad n =>
(f ~> n) -> (m ~> n) -> FreeT f m ~> n
eitherFreeT_ f x -> FreeT g m x
f ~> FreeT g m
k m x -> FreeT g m x
m ~> FreeT g m
forall (m :: * -> *) (f :: * -> *). Functor m => m ~> FreeT f m
inr

instance (Traversable f, Traversable m) => Traversable (FreeT' f m) where
  traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FreeT' f m a -> f (FreeT' f m b)
traverse a -> f b
f (WrapFreeT' FreeT m f a
mx) = FreeT m f b -> FreeT' f m b
forall (m :: * -> *) (f :: * -> *) b. FreeT f m b -> FreeT' m f b
WrapFreeT' (FreeT m f b -> FreeT' f m b)
-> f (FreeT m f b) -> f (FreeT' f m b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f b) -> FreeT m f a -> f (FreeT m f b)
forall (f :: * -> *) (m :: * -> *) (g :: * -> *) a b.
(Traversable f, Traversable m, Applicative g) =>
(a -> g b) -> FreeT f m a -> g (FreeT f m b)
traverseFreeT_ a -> f b
f FreeT m f a
mx

instance Functor m => FFunctor (FreeT' m) where
  ffmap :: forall (g :: * -> *) (h :: * -> *) x.
(Functor g, Functor h) =>
(g ~> h) -> FreeT' m g x -> FreeT' m h x
ffmap g ~> h
f = FreeT h m x -> FreeT' m h x
forall (m :: * -> *) (f :: * -> *) b. FreeT f m b -> FreeT' m f b
WrapFreeT' (FreeT h m x -> FreeT' m h x)
-> (FreeT' m g x -> FreeT h m x) -> FreeT' m g x -> FreeT' m h x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (g ~> h) -> FreeT g m ~> FreeT h m
forall (f :: * -> *) (g :: * -> *) (m :: * -> *).
(Functor g, Functor m) =>
(f ~> g) -> FreeT f m ~> FreeT g m
transFreeT_ g x -> h x
g ~> h
f (FreeT g m x -> FreeT h m x)
-> (FreeT' m g x -> FreeT g m x) -> FreeT' m g x -> FreeT h m x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FreeT' m g x -> FreeT g m x
forall (m :: * -> *) (f :: * -> *) b. FreeT' m f b -> FreeT f m b
unwrapFreeT'

instance Monad m => FMonad (FreeT' m) where
  fpure :: forall g. Functor g => g ~> FreeT' m g
  fpure :: forall (g :: * -> *). Functor g => g ~> FreeT' m g
fpure = FreeT g m x -> FreeT' m g x
forall (m :: * -> *) (f :: * -> *) b. FreeT f m b -> FreeT' m f b
WrapFreeT' (FreeT g m x -> FreeT' m g x)
-> (g x -> FreeT g m x) -> g x -> FreeT' m g x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. g x -> FreeT g m x
g ~> FreeT g m
forall (m :: * -> *) (f :: * -> *).
(Monad m, Functor f) =>
f ~> FreeT f m
fpureFst

  fbind :: forall g h a. (Functor g, Functor h) => (g ~> FreeT' m h) -> FreeT' m g a -> FreeT' m h a
  fbind :: forall (g :: * -> *) (h :: * -> *) a.
(Functor g, Functor h) =>
(g ~> FreeT' m h) -> FreeT' m g a -> FreeT' m h a
fbind g ~> FreeT' m h
k = FreeT h m a -> FreeT' m h a
forall (m :: * -> *) (f :: * -> *) b. FreeT f m b -> FreeT' m f b
WrapFreeT' (FreeT h m a -> FreeT' m h a)
-> (FreeT' m g a -> FreeT h m a) -> FreeT' m g a -> FreeT' m h a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (g ~> FreeT h m) -> FreeT g m ~> FreeT h m
forall (m :: * -> *) (f :: * -> *) (g :: * -> *).
(Monad m, Functor f, Functor g) =>
(f ~> FreeT g m) -> FreeT f m ~> FreeT g m
fbindFst (FreeT' m h x -> FreeT h m x
forall (m :: * -> *) (f :: * -> *) b. FreeT' m f b -> FreeT f m b
unwrapFreeT' (FreeT' m h x -> FreeT h m x)
-> (g x -> FreeT' m h x) -> g x -> FreeT h m x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. g x -> FreeT' m h x
g ~> FreeT' m h
k) (FreeT g m a -> FreeT h m a)
-> (FreeT' m g a -> FreeT g m a) -> FreeT' m g a -> FreeT h m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FreeT' m g a -> FreeT g m a
forall (m :: * -> *) (f :: * -> *) b. FreeT' m f b -> FreeT f m b
unwrapFreeT'