{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wno-orphans #-}
{-|
Module:      TextShow.Control.Monad.Trans
Copyright:   (C) 2014-2017 Ryan Scott
License:     BSD-style (see the file LICENSE)
Maintainer:  Ryan Scott
Stability:   Provisional
Portability: GHC

'TextShow' instances for monad transformers.

/Since: 2/
-}
module TextShow.Control.Monad.Trans () where

import           Control.Monad.Trans.Except              (ExceptT(..))
import           Control.Monad.Trans.Identity            (IdentityT(..))
import           Control.Monad.Trans.Maybe               (MaybeT(..))
import qualified Control.Monad.Trans.Writer.Lazy   as WL (WriterT(..))
import qualified Control.Monad.Trans.Writer.Strict as WS (WriterT(..))

import           TextShow (TextShow(..), TextShow1(..), TextShow2(..),
                           Builder, showbPrec1, showbUnaryWith)
import           TextShow.Utils (liftShowbUnaryWith)

liftMShowbUnaryWith :: (TextShow1 m, TextShow1 f)
                    => (Int -> a -> Builder) -> ([a] -> Builder)
                    -> Builder -> Int -> m (f a) -> Builder
liftMShowbUnaryWith :: forall (m :: * -> *) (f :: * -> *) a.
(TextShow1 m, TextShow1 f) =>
(Int -> a -> Builder)
-> ([a] -> Builder) -> Builder -> Int -> m (f a) -> Builder
liftMShowbUnaryWith Int -> a -> Builder
sp [a] -> Builder
sl Builder
name Int
p m (f a)
m =
    forall a. (Int -> a -> Builder) -> Builder -> Int -> a -> Builder
showbUnaryWith (forall (f :: * -> *) a.
TextShow1 f =>
(Int -> a -> Builder) -> ([a] -> Builder) -> Int -> f a -> Builder
liftShowbPrec (forall (f :: * -> *) a.
TextShow1 f =>
(Int -> a -> Builder) -> ([a] -> Builder) -> Int -> f a -> Builder
liftShowbPrec Int -> a -> Builder
sp [a] -> Builder
sl)
                                  (forall (f :: * -> *) a.
TextShow1 f =>
(Int -> a -> Builder) -> ([a] -> Builder) -> [f a] -> Builder
liftShowbList Int -> a -> Builder
sp [a] -> Builder
sl)) Builder
name Int
p m (f a)
m
{-# INLINE liftMShowbUnaryWith #-}

liftShowbWriterTPrec :: (TextShow1 m, TextShow w)
                     => (Int -> a -> Builder) -> ([a] -> Builder)
                     -> Int -> m (a, w) -> Builder
liftShowbWriterTPrec :: forall (m :: * -> *) w a.
(TextShow1 m, TextShow w) =>
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> m (a, w) -> Builder
liftShowbWriterTPrec Int -> a -> Builder
sp [a] -> Builder
sl Int
p m (a, w)
m =
    forall a. (Int -> a -> Builder) -> Builder -> Int -> a -> Builder
showbUnaryWith (forall (f :: * -> *) a.
TextShow1 f =>
(Int -> a -> Builder) -> ([a] -> Builder) -> Int -> f a -> Builder
liftShowbPrec (forall (f :: * -> * -> *) a b.
TextShow2 f =>
(Int -> a -> Builder)
-> ([a] -> Builder)
-> (Int -> b -> Builder)
-> ([b] -> Builder)
-> Int
-> f a b
-> Builder
liftShowbPrec2 Int -> a -> Builder
sp [a] -> Builder
sl forall a. TextShow a => Int -> a -> Builder
showbPrec forall a. TextShow a => [a] -> Builder
showbList)
                                  (forall (f :: * -> * -> *) a b.
TextShow2 f =>
(Int -> a -> Builder)
-> ([a] -> Builder)
-> (Int -> b -> Builder)
-> ([b] -> Builder)
-> [f a b]
-> Builder
liftShowbList2 Int -> a -> Builder
sp [a] -> Builder
sl forall a. TextShow a => Int -> a -> Builder
showbPrec forall a. TextShow a => [a] -> Builder
showbList))
                   Builder
"WriterT" Int
p m (a, w)
m
{-# INLINE liftShowbWriterTPrec #-}

-- | /Since: 2/
instance (TextShow e, TextShow1 m, TextShow a) => TextShow (ExceptT e m a) where
    showbPrec :: Int -> ExceptT e m a -> Builder
showbPrec = forall (f :: * -> *) a.
(TextShow1 f, TextShow a) =>
Int -> f a -> Builder
showbPrec1
    {-# INLINE showbPrec #-}

-- | /Since: 2/
instance (TextShow e, TextShow1 m) => TextShow1 (ExceptT e m) where
    liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> ExceptT e m a -> Builder
liftShowbPrec Int -> a -> Builder
sp [a] -> Builder
sl Int
p (ExceptT m (Either e a)
m) = forall (m :: * -> *) (f :: * -> *) a.
(TextShow1 m, TextShow1 f) =>
(Int -> a -> Builder)
-> ([a] -> Builder) -> Builder -> Int -> m (f a) -> Builder
liftMShowbUnaryWith Int -> a -> Builder
sp [a] -> Builder
sl Builder
"ExceptT" Int
p m (Either e a)
m
    {-# INLINE liftShowbPrec #-}

-- | /Since: 2/
instance (TextShow1 f, TextShow a) => TextShow (IdentityT f a) where
    showbPrec :: Int -> IdentityT f a -> Builder
showbPrec = forall (f :: * -> *) a.
(TextShow1 f, TextShow a) =>
Int -> f a -> Builder
showbPrec1
    {-# INLINE showbPrec #-}

-- | /Since: 2/
instance TextShow1 f => TextShow1 (IdentityT f) where
    liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> IdentityT f a -> Builder
liftShowbPrec Int -> a -> Builder
sp [a] -> Builder
sl Int
p (IdentityT f a
m) = forall (m :: * -> *) a.
TextShow1 m =>
(Int -> a -> Builder)
-> ([a] -> Builder) -> Builder -> Int -> m a -> Builder
liftShowbUnaryWith Int -> a -> Builder
sp [a] -> Builder
sl Builder
"IdentityT" Int
p f a
m
    {-# INLINE liftShowbPrec #-}

-- | /Since: 2/
instance (TextShow1 m, TextShow a) => TextShow (MaybeT m a) where
    showbPrec :: Int -> MaybeT m a -> Builder
showbPrec = forall (f :: * -> *) a.
(TextShow1 f, TextShow a) =>
Int -> f a -> Builder
showbPrec1
    {-# INLINE showbPrec #-}

-- | /Since: 2/
instance TextShow1 m => TextShow1 (MaybeT m) where
    liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> MaybeT m a -> Builder
liftShowbPrec Int -> a -> Builder
sp [a] -> Builder
sl Int
p (MaybeT m (Maybe a)
m) = forall (m :: * -> *) (f :: * -> *) a.
(TextShow1 m, TextShow1 f) =>
(Int -> a -> Builder)
-> ([a] -> Builder) -> Builder -> Int -> m (f a) -> Builder
liftMShowbUnaryWith Int -> a -> Builder
sp [a] -> Builder
sl Builder
"MaybeT" Int
p m (Maybe a)
m
    {-# INLINE liftShowbPrec #-}

-- | /Since: 2/
instance (TextShow w, TextShow1 m, TextShow a) => TextShow (WL.WriterT w m a) where
    showbPrec :: Int -> WriterT w m a -> Builder
showbPrec = forall (f :: * -> *) a.
(TextShow1 f, TextShow a) =>
Int -> f a -> Builder
showbPrec1
    {-# INLINE showbPrec #-}

-- | /Since: 2/
instance (TextShow w, TextShow1 m) => TextShow1 (WL.WriterT w m) where
    liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> WriterT w m a -> Builder
liftShowbPrec Int -> a -> Builder
sp [a] -> Builder
sl Int
p (WL.WriterT m (a, w)
m) = forall (m :: * -> *) w a.
(TextShow1 m, TextShow w) =>
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> m (a, w) -> Builder
liftShowbWriterTPrec Int -> a -> Builder
sp [a] -> Builder
sl Int
p m (a, w)
m
    {-# INLINE liftShowbPrec #-}

-- | /Since: 2/
instance (TextShow w, TextShow1 m, TextShow a) => TextShow (WS.WriterT w m a) where
    showbPrec :: Int -> WriterT w m a -> Builder
showbPrec = forall (f :: * -> *) a.
(TextShow1 f, TextShow a) =>
Int -> f a -> Builder
showbPrec1
    {-# INLINE showbPrec #-}

-- | /Since: 2/
instance (TextShow w, TextShow1 m) => TextShow1 (WS.WriterT w m) where
    liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> WriterT w m a -> Builder
liftShowbPrec Int -> a -> Builder
sp [a] -> Builder
sl Int
p (WS.WriterT m (a, w)
m) = forall (m :: * -> *) w a.
(TextShow1 m, TextShow w) =>
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> m (a, w) -> Builder
liftShowbWriterTPrec Int -> a -> Builder
sp [a] -> Builder
sl Int
p m (a, w)
m
    {-# INLINE liftShowbPrec #-}