{-# LANGUAGE Safe #-}
module Text.Chatty.Expansion where
import Control.Applicative
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
class Monad e => ChExpand e where
expand :: String -> e String
newtype NullExpanderT m a = NullExpander { NullExpanderT m a -> m a
runNullExpanderT :: m a }
instance Monad m => Monad (NullExpanderT m) where
return :: a -> NullExpanderT m a
return = m a -> NullExpanderT m a
forall (m :: * -> *) a. m a -> NullExpanderT m a
NullExpander (m a -> NullExpanderT m a) -> (a -> m a) -> a -> NullExpanderT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(NullExpander m a
ne) >>= :: NullExpanderT m a -> (a -> NullExpanderT m b) -> NullExpanderT m b
>>= a -> NullExpanderT m b
f = m b -> NullExpanderT m b
forall (m :: * -> *) a. m a -> NullExpanderT m a
NullExpander (m b -> NullExpanderT m b) -> m b -> NullExpanderT m b
forall a b. (a -> b) -> a -> b
$ do a
ne' <- m a
ne; NullExpanderT m b -> m b
forall (m :: * -> *) a. NullExpanderT m a -> m a
runNullExpanderT (a -> NullExpanderT m b
f a
ne')
instance MonadTrans NullExpanderT where
lift :: m a -> NullExpanderT m a
lift = m a -> NullExpanderT m a
forall (m :: * -> *) a. m a -> NullExpanderT m a
NullExpander
instance Functor m => Functor (NullExpanderT m) where
fmap :: (a -> b) -> NullExpanderT m a -> NullExpanderT m b
fmap a -> b
f (NullExpander m a
ne) = m b -> NullExpanderT m b
forall (m :: * -> *) a. m a -> NullExpanderT m a
NullExpander (m b -> NullExpanderT m b) -> m b -> NullExpanderT m b
forall a b. (a -> b) -> a -> b
$ (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f m a
ne
instance (Functor m, Monad m) => Applicative (NullExpanderT m) where
<*> :: NullExpanderT m (a -> b) -> NullExpanderT m a -> NullExpanderT m b
(<*>) = NullExpanderT m (a -> b) -> NullExpanderT m a -> NullExpanderT m b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap
pure :: a -> NullExpanderT m a
pure = a -> NullExpanderT m a
forall (m :: * -> *) a. Monad m => a -> m a
return
instance MonadIO m => MonadIO (NullExpanderT m) where
liftIO :: IO a -> NullExpanderT m a
liftIO = m a -> NullExpanderT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> NullExpanderT m a)
-> (IO a -> m a) -> IO a -> NullExpanderT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
instance Monad m => ChExpand (NullExpanderT m) where
expand :: String -> NullExpanderT m String
expand = String -> NullExpanderT m String
forall (m :: * -> *) a. Monad m => a -> m a
return
withExpansion :: Monad m => NullExpanderT m a -> m a
withExpansion :: NullExpanderT m a -> m a
withExpansion = NullExpanderT m a -> m a
forall (m :: * -> *) a. NullExpanderT m a -> m a
runNullExpanderT