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 { runNullExpanderT :: m a }
instance Monad m => Monad (NullExpanderT m) where
return = NullExpander . return
(NullExpander ne) >>= f = NullExpander $ do ne' <- ne; runNullExpanderT (f ne')
instance MonadTrans NullExpanderT where
lift = NullExpander
instance Functor m => Functor (NullExpanderT m) where
fmap f (NullExpander ne) = NullExpander $ fmap f ne
instance (Functor m, Monad m) => Applicative (NullExpanderT m) where
(<*>) = ap
pure = return
instance MonadIO m => MonadIO (NullExpanderT m) where
liftIO = lift . liftIO
instance Monad m => ChExpand (NullExpanderT m) where
expand = return
withExpansion :: Monad m => NullExpanderT m a -> m a
withExpansion = runNullExpanderT