{-# LANGUAGE DeriveFunctor #-}
module Test.Hspec.Core.Formatters.V1.Free where

import           Prelude ()
import           Test.Hspec.Core.Compat

data Free f a = Free (f (Free f a)) | Pure a
  deriving forall a b. a -> Free f b -> Free f a
forall a b. (a -> b) -> Free f a -> Free f b
forall (f :: * -> *) a b. Functor f => a -> Free f b -> Free f a
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> Free f a -> Free f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Free f b -> Free f a
$c<$ :: forall (f :: * -> *) a b. Functor f => a -> Free f b -> Free f a
fmap :: forall a b. (a -> b) -> Free f a -> Free f b
$cfmap :: forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> Free f a -> Free f b
Functor

instance Functor f => Applicative (Free f) where
  pure :: forall a. a -> Free f a
pure = forall (f :: * -> *) a. a -> Free f a
Pure
  Pure a -> b
f <*> :: forall a b. Free f (a -> b) -> Free f a -> Free f b
<*> Pure a
a = forall (f :: * -> *) a. a -> Free f a
Pure (a -> b
f a
a)
  Pure a -> b
f <*> Free f (Free f a)
m = forall (f :: * -> *) a. f (Free f a) -> Free f a
Free (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (Free f a)
m)
  Free f (Free f (a -> b))
m <*> Free f a
b = forall (f :: * -> *) a. f (Free f a) -> Free f a
Free (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Free f a
b) f (Free f (a -> b))
m)

instance Functor f => Monad (Free f) where
  return :: forall a. a -> Free f a
return = forall (f :: * -> *) a. Applicative f => a -> f a
pure
  Pure a
a >>= :: forall a b. Free f a -> (a -> Free f b) -> Free f b
>>= a -> Free f b
f = a -> Free f b
f a
a
  Free f (Free f a)
m >>= a -> Free f b
f = forall (f :: * -> *) a. f (Free f a) -> Free f a
Free (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Free f b
f) f (Free f a)
m)

liftF :: Functor f => f a -> Free f a
liftF :: forall (f :: * -> *) a. Functor f => f a -> Free f a
liftF f a
command = forall (f :: * -> *) a. f (Free f a) -> Free f a
Free (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. a -> Free f a
Pure f a
command)