{-# OPTIONS_GHC -Wall #-}
module Text.ShowF where
import Data.Functor ((<$>))
class ShowF f where
showF :: Show a => f a -> String
showsPrecF :: Show a => Int -> f a -> ShowS
showsPrecF Int
_ f a
x String
s = f a -> String
forall a. Show a => f a -> String
forall (f :: * -> *) a. (ShowF f, Show a) => f a -> String
showF f a
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s
showF f a
x = f a -> ShowS
forall (f :: * -> *) a. (ShowF f, Show a) => f a -> ShowS
showsF f a
x String
""
newtype WrapShowF f a = WrapShowF (f a)
instance (ShowF f, Show a) => Show (WrapShowF f a) where
showsPrec :: Int -> WrapShowF f a -> ShowS
showsPrec Int
p (WrapShowF f a
fa) = Int -> f a -> ShowS
forall a. Show a => Int -> f a -> ShowS
forall (f :: * -> *) a. (ShowF f, Show a) => Int -> f a -> ShowS
showsPrecF Int
p f a
fa
showsF :: (ShowF f, Show a) => f a -> ShowS
showsF :: forall (f :: * -> *) a. (ShowF f, Show a) => f a -> ShowS
showsF = Int -> f a -> ShowS
forall a. Show a => Int -> f a -> ShowS
forall (f :: * -> *) a. (ShowF f, Show a) => Int -> f a -> ShowS
showsPrecF Int
0
showsApp1 :: Show a => String -> Int -> a -> ShowS
showsApp1 :: forall a. Show a => String -> Int -> a -> ShowS
showsApp1 String
s Int
p a
a = String -> Int -> ShowS -> ShowS
strApp1 String
s Int
p (Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a
a)
showsFApp1 :: (ShowF f, Show a) => String -> Int -> f a -> ShowS
showsFApp1 :: forall (f :: * -> *) a.
(ShowF f, Show a) =>
String -> Int -> f a -> ShowS
showsFApp1 String
s Int
p f a
fa = String -> Int -> ShowS -> ShowS
strApp1 String
s Int
p (Int -> f a -> ShowS
forall a. Show a => Int -> f a -> ShowS
forall (f :: * -> *) a. (ShowF f, Show a) => Int -> f a -> ShowS
showsPrecF Int
11 f a
fa)
showsFComp1 :: (Functor g, ShowF g, ShowF f, Show a) => String -> Int -> g (f a) -> ShowS
showsFComp1 :: forall (g :: * -> *) (f :: * -> *) a.
(Functor g, ShowF g, ShowF f, Show a) =>
String -> Int -> g (f a) -> ShowS
showsFComp1 String
s Int
p g (f a)
gfa = String -> Int -> g (WrapShowF f a) -> ShowS
forall (f :: * -> *) a.
(ShowF f, Show a) =>
String -> Int -> f a -> ShowS
showsFApp1 String
s Int
p (f a -> WrapShowF f a
forall (f :: * -> *) a. f a -> WrapShowF f a
WrapShowF (f a -> WrapShowF f a) -> g (f a) -> g (WrapShowF f a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> g (f a)
gfa)
strApp1 :: String -> Int -> ShowS -> ShowS
strApp1 :: String -> Int -> ShowS -> ShowS
strApp1 String
s Int
p ShowS
sh = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
s ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' ' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
sh