-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Combinators to write Show instances
--   
--   A minimal pretty-printing library for Show instances in Haskell.
@package show-combinators
@version 0.1.0.0


-- | Combinators for <a>Show</a>
--   
--   The combinators below can be used to write <a>Show</a> instances.
--   
--   The following type illustrates the common use cases.
--   
--   <pre>
--   data MyType a
--     = C a a                   -- a regular constructor
--     | a :+: a                 -- an infix constructor
--     | R { f1 :: a, f2 :: a }  -- a record
--   
--   infixl 4 :+:
--   
--   instance <a>Show</a> a =&gt; <a>Show</a> (MyType a) where
--     <a>showsPrec</a> = <a>flip</a> precShows where
--       precShows (C a b) = <a>showCon</a> <a>C</a> <a>@|</a> a <a>@|</a> b
--       precShows (c :+: d) = <a>showInfix'</a> ":+:" 4 c d
--       precShows (R {f1 = e, f2 = f}) =
--         <a>showRecord</a> <a>R</a> ("f1" <a>.=.</a> e <a>&amp;|</a> "f2" <a>.=.</a> f)
--   </pre>
module Text.Show.Combinators

-- | Type of strings representing expressions, parameterized by the
--   surrounding precedence level.
--   
--   This is the return type of <tt><a>flip</a> <a>showsPrec</a></tt>.
type PrecShowS = Int -> ShowS

-- | Show a constructor.
showCon :: String -> PrecShowS

-- | Show a function application.
showApp :: PrecShowS -> PrecShowS -> PrecShowS
infixl 2 `showApp`

-- | Show a function application.
--   
--   This is an infix shorthand for <a>showApp</a> when the argument type
--   is an instance of <a>Show</a>.
--   
--   <pre>
--   showF @| x = showApp showF (flip showsPrec x)
--   </pre>
(@|) :: Show a => PrecShowS -> a -> PrecShowS
infixl 2 @|

-- | Show an applied infix operator with a given precedence.
showInfix :: String -> Int -> PrecShowS -> PrecShowS -> PrecShowS

-- | Show an applied infix operator with a given precedence.
--   
--   This is a shorthand for <a>showInfix</a> when the arguments types are
--   instances of <a>Show</a>.
--   
--   <pre>
--   showInfix' op prec x y =
--     showInfix op prec (flip showsPrec x) (flip showsPrec y)
--   </pre>
showInfix' :: (Show a, Show b) => String -> Int -> a -> b -> PrecShowS

-- | Strings representing a set of record fields separated by commas. They
--   can be constructed using (<a>.=.</a>) and (<a>@|</a>), or using
--   <a>showField</a> and <a>appendFields</a>.
type ShowFields = ShowS

-- | Show a record. The first argument is the constructor name. The second
--   represents the set of record fields.
showRecord :: String -> ShowFields -> PrecShowS

-- | Show a single record field: a field name and a value separated by
--   <tt>'='</tt>.
showField :: String -> PrecShowS -> ShowFields

-- | Show a single record field: a field name and a value separated by
--   <tt>'='</tt>.
--   
--   This is an infix shorthand for <a>showField</a> when the value type is
--   an instance of <a>Show</a>.
--   
--   <pre>
--   field .=. x = showField field (flip showsPrec x)
--   </pre>
(.=.) :: Show a => String -> a -> ShowFields
infixr 8 .=.

-- | Empty set of record fields.
noFields :: ShowFields

-- | Separate two nonempty sets of record fields by a comma.
appendFields :: ShowFields -> ShowFields -> ShowFields
infixr 1 `appendFields`

-- | An infix synonym of <a>appendFields</a>.
(&|) :: ShowFields -> ShowFields -> ShowFields
infixr 1 &|
