{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE DataKinds             #-}
{-# LANGUAGE DeriveDataTypeable    #-}
{-# LANGUAGE DeriveFoldable        #-}
{-# LANGUAGE DeriveFunctor         #-}
{-# LANGUAGE DeriveGeneric         #-}
{-# LANGUAGE DeriveTraversable     #-}
{-# LANGUAGE EmptyCase             #-}
{-# LANGUAGE EmptyDataDecls        #-}
{-# LANGUAGE FlexibleContexts      #-}
{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE GADTs                 #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE PolyKinds             #-}
{-# LANGUAGE ScopedTypeVariables   #-}
{-# LANGUAGE StandaloneDeriving    #-}
{-# LANGUAGE TypeOperators         #-}
{-# LANGUAGE TemplateHaskell       #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE TypeSynonymInstances  #-}
{-# LANGUAGE UndecidableInstances  #-}

#if __GLASGOW_HASKELL__ >= 800
{-# LANGUAGE DeriveLift           #-}
#endif

{-|
Module:      TextShow.Generic
Copyright:   (C) 2014-2017 Ryan Scott
License:     BSD-style (see the file LICENSE)
Maintainer:  Ryan Scott
Stability:   Provisional
Portability: GHC

Generic versions of 'TextShow' and 'TextShow1' class functions, as an alternative to
"TextShow.TH", which uses Template Haskell. Because there is no 'Generic2'
class, 'TextShow2' cannot be implemented generically.

This implementation is loosely based off of the @Generics.Deriving.Show@ module
from the @generic-deriving@ library.

/Since: 2/
-}
module TextShow.Generic (
      -- * Generic adapter newtypes
      FromGeneric(..)
    , FromGeneric1(..)

      -- * Generic @show@ functions
      -- $generics

      -- ** Understanding a compiler error
      -- $generic_err
    , genericShowt
    , genericShowtl
    , genericShowtPrec
    , genericShowtlPrec
    , genericShowtList
    , genericShowtlList
    , genericShowb
    , genericShowbPrec
    , genericShowbList
    , genericPrintT
    , genericPrintTL
    , genericHPrintT
    , genericHPrintTL
    , genericLiftShowbPrec
    , genericShowbPrec1
      -- * Internals
      -- ** 'Builder'
    , GTextShowB(..)
    , GTextShowConB(..)
    , ShowFunsB(..)
      -- ** Strict 'TS.Text'
    , GTextShowT(..)
    , GTextShowConT(..)
    , ShowFunsT(..)
      -- ** Lazy 'TL.Text'
    , GTextShowTL(..)
    , GTextShowConTL(..)
    , ShowFunsTL(..)
      -- ** Other internals
    , IsNullary(..)
    , ConType(..)
    , Zero
    , One
    ) where

import           Data.Data (Data, Typeable)
import           Data.Functor.Contravariant.Compat (Contravariant(..))
import qualified Data.Text    as TS (Text, pack, singleton)
import qualified Data.Text.IO as TS (putStrLn, hPutStrLn)
import qualified Data.Text.Lazy    as TL (Text, pack, singleton)
import qualified Data.Text.Lazy.IO as TL (putStrLn, hPutStrLn)
import qualified Data.Text.Lazy.Builder as TB (fromString, singleton)
import           Data.Text.Lazy.Builder (Builder)

import           Generics.Deriving.Base
#if !defined(__LANGUAGE_DERIVE_GENERIC1__)
import qualified Generics.Deriving.TH as Generics
#endif

import           GHC.Exts (Char(C#), Double(D#), Float(F#), Int(I#), Word(W#))
import           GHC.Show (appPrec, appPrec1)

import           Language.Haskell.TH.Lift

import           Prelude ()
import           Prelude.Compat

import           System.IO (Handle)

import           TextShow.Classes (TextShow(..), TextShow1(..),
                                   showbListWith, showbParen, showbSpace,
                                   showtListWith, showtParen, showtSpace,
                                   showtlListWith, showtlParen, showtlSpace,
                                   liftShowtPrec, liftShowtlPrec)
import           TextShow.Instances ()
import           TextShow.TH.Internal (deriveTextShow)
import           TextShow.Utils (isInfixDataCon, isSymVar, isTupleString)

{- $generics

'TextShow' instances can be easily defined for data types that are 'Generic' instances.
If you are using GHC 8.6 or later, the easiest way to do this is to use the
@DerivingVia@ extension.

@
{-# LANGUAGE DeriveGeneric, DerivingVia #-}
import GHC.Generics
import TextShow
import TextShow.Generic

data D a = D a
  deriving ('Generic', 'Generic1')
  deriving 'TextShow'  via 'FromGeneric'  (D a)
  deriving 'TextShow1' via 'FromGeneric1' D
@

Or, if you are using a version of GHC older than 8.6, one can alternatively
define these instances like so:

@
instance 'TextShow' a => 'TextShow' (D a) where
    'showbPrec' = 'genericShowbPrec'

instance 'TextShow1' D where
    'liftShowbPrec' = 'genericLiftShowbPrec'
@
-}

{- $generic_err

Suppose you intend to define a 'TextShow' instance via 'FromGeneric':

@
data Oops = Oops
  deriving 'TextShow' via 'FromGeneric' Oops
    -- forgot to add \"deriving Generic\" here!
@

If you forget to add a @deriving 'Generic'@ clause to your data type, at
compile-time, you might get an error message that begins roughly as follows:

@
No instance for ('GTextShowB' 'Zero' ('Rep' Oops))
@

This error can be confusing, but don't let it intimidate you. The correct fix is
simply to add the missing \"@deriving 'Generic'@\" clause.

Similarly, if the compiler complains about not having an instance for @('GTextShowB'
'One' ('Rep1' Oops1))@, add a \"@deriving 'Generic1'@\" clause.
-}

-- | An adapter newtype, suitable for @DerivingVia@.
-- The 'TextShow' instance for 'FromGeneric' leverages a 'Generic'-based
-- default. That is,
--
-- @
-- 'showbPrec' p ('FromGeneric' x) = 'genericShowbPrec' p x
-- @
--
-- /Since: 3.7.4/
newtype FromGeneric a = FromGeneric { FromGeneric a -> a
fromGeneric :: a }
  deriving ( Typeable (FromGeneric a)
DataType
Constr
Typeable (FromGeneric a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> FromGeneric a -> c (FromGeneric a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (FromGeneric a))
-> (FromGeneric a -> Constr)
-> (FromGeneric a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (FromGeneric a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (FromGeneric a)))
-> ((forall b. Data b => b -> b) -> FromGeneric a -> FromGeneric a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> FromGeneric a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> FromGeneric a -> r)
-> (forall u. (forall d. Data d => d -> u) -> FromGeneric a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> FromGeneric a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> FromGeneric a -> m (FromGeneric a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> FromGeneric a -> m (FromGeneric a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> FromGeneric a -> m (FromGeneric a))
-> Data (FromGeneric a)
FromGeneric a -> DataType
FromGeneric a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (FromGeneric a))
(forall b. Data b => b -> b) -> FromGeneric a -> FromGeneric a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FromGeneric a -> c (FromGeneric a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (FromGeneric a)
forall a. Data a => Typeable (FromGeneric a)
forall a. Data a => FromGeneric a -> DataType
forall a. Data a => FromGeneric a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> FromGeneric a -> FromGeneric a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> FromGeneric a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> FromGeneric a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FromGeneric a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FromGeneric a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> FromGeneric a -> m (FromGeneric a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> FromGeneric a -> m (FromGeneric a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (FromGeneric a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FromGeneric a -> c (FromGeneric a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (FromGeneric a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (FromGeneric a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> FromGeneric a -> u
forall u. (forall d. Data d => d -> u) -> FromGeneric a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FromGeneric a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FromGeneric a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> FromGeneric a -> m (FromGeneric a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> FromGeneric a -> m (FromGeneric a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (FromGeneric a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FromGeneric a -> c (FromGeneric a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (FromGeneric a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (FromGeneric a))
$cFromGeneric :: Constr
$tFromGeneric :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> FromGeneric a -> m (FromGeneric a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> FromGeneric a -> m (FromGeneric a)
gmapMp :: (forall d. Data d => d -> m d)
-> FromGeneric a -> m (FromGeneric a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> FromGeneric a -> m (FromGeneric a)
gmapM :: (forall d. Data d => d -> m d)
-> FromGeneric a -> m (FromGeneric a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> FromGeneric a -> m (FromGeneric a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> FromGeneric a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> FromGeneric a -> u
gmapQ :: (forall d. Data d => d -> u) -> FromGeneric a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> FromGeneric a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FromGeneric a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FromGeneric a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FromGeneric a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FromGeneric a -> r
gmapT :: (forall b. Data b => b -> b) -> FromGeneric a -> FromGeneric a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> FromGeneric a -> FromGeneric a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (FromGeneric a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (FromGeneric a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (FromGeneric a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (FromGeneric a))
dataTypeOf :: FromGeneric a -> DataType
$cdataTypeOf :: forall a. Data a => FromGeneric a -> DataType
toConstr :: FromGeneric a -> Constr
$ctoConstr :: forall a. Data a => FromGeneric a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (FromGeneric a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (FromGeneric a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FromGeneric a -> c (FromGeneric a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FromGeneric a -> c (FromGeneric a)
$cp1Data :: forall a. Data a => Typeable (FromGeneric a)
Data
           , FromGeneric a -> FromGeneric a -> Bool
(FromGeneric a -> FromGeneric a -> Bool)
-> (FromGeneric a -> FromGeneric a -> Bool) -> Eq (FromGeneric a)
forall a. Eq a => FromGeneric a -> FromGeneric a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FromGeneric a -> FromGeneric a -> Bool
$c/= :: forall a. Eq a => FromGeneric a -> FromGeneric a -> Bool
== :: FromGeneric a -> FromGeneric a -> Bool
$c== :: forall a. Eq a => FromGeneric a -> FromGeneric a -> Bool
Eq
           , FromGeneric a -> Bool
(a -> m) -> FromGeneric a -> m
(a -> b -> b) -> b -> FromGeneric a -> b
(forall m. Monoid m => FromGeneric m -> m)
-> (forall m a. Monoid m => (a -> m) -> FromGeneric a -> m)
-> (forall m a. Monoid m => (a -> m) -> FromGeneric a -> m)
-> (forall a b. (a -> b -> b) -> b -> FromGeneric a -> b)
-> (forall a b. (a -> b -> b) -> b -> FromGeneric a -> b)
-> (forall b a. (b -> a -> b) -> b -> FromGeneric a -> b)
-> (forall b a. (b -> a -> b) -> b -> FromGeneric a -> b)
-> (forall a. (a -> a -> a) -> FromGeneric a -> a)
-> (forall a. (a -> a -> a) -> FromGeneric a -> a)
-> (forall a. FromGeneric a -> [a])
-> (forall a. FromGeneric a -> Bool)
-> (forall a. FromGeneric a -> Int)
-> (forall a. Eq a => a -> FromGeneric a -> Bool)
-> (forall a. Ord a => FromGeneric a -> a)
-> (forall a. Ord a => FromGeneric a -> a)
-> (forall a. Num a => FromGeneric a -> a)
-> (forall a. Num a => FromGeneric a -> a)
-> Foldable FromGeneric
forall a. Eq a => a -> FromGeneric a -> Bool
forall a. Num a => FromGeneric a -> a
forall a. Ord a => FromGeneric a -> a
forall m. Monoid m => FromGeneric m -> m
forall a. FromGeneric a -> Bool
forall a. FromGeneric a -> Int
forall a. FromGeneric a -> [a]
forall a. (a -> a -> a) -> FromGeneric a -> a
forall m a. Monoid m => (a -> m) -> FromGeneric a -> m
forall b a. (b -> a -> b) -> b -> FromGeneric a -> b
forall a b. (a -> b -> b) -> b -> FromGeneric a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: FromGeneric a -> a
$cproduct :: forall a. Num a => FromGeneric a -> a
sum :: FromGeneric a -> a
$csum :: forall a. Num a => FromGeneric a -> a
minimum :: FromGeneric a -> a
$cminimum :: forall a. Ord a => FromGeneric a -> a
maximum :: FromGeneric a -> a
$cmaximum :: forall a. Ord a => FromGeneric a -> a
elem :: a -> FromGeneric a -> Bool
$celem :: forall a. Eq a => a -> FromGeneric a -> Bool
length :: FromGeneric a -> Int
$clength :: forall a. FromGeneric a -> Int
null :: FromGeneric a -> Bool
$cnull :: forall a. FromGeneric a -> Bool
toList :: FromGeneric a -> [a]
$ctoList :: forall a. FromGeneric a -> [a]
foldl1 :: (a -> a -> a) -> FromGeneric a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> FromGeneric a -> a
foldr1 :: (a -> a -> a) -> FromGeneric a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> FromGeneric a -> a
foldl' :: (b -> a -> b) -> b -> FromGeneric a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> FromGeneric a -> b
foldl :: (b -> a -> b) -> b -> FromGeneric a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> FromGeneric a -> b
foldr' :: (a -> b -> b) -> b -> FromGeneric a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> FromGeneric a -> b
foldr :: (a -> b -> b) -> b -> FromGeneric a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> FromGeneric a -> b
foldMap' :: (a -> m) -> FromGeneric a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> FromGeneric a -> m
foldMap :: (a -> m) -> FromGeneric a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> FromGeneric a -> m
fold :: FromGeneric m -> m
$cfold :: forall m. Monoid m => FromGeneric m -> m
Foldable
           , a -> FromGeneric b -> FromGeneric a
(a -> b) -> FromGeneric a -> FromGeneric b
(forall a b. (a -> b) -> FromGeneric a -> FromGeneric b)
-> (forall a b. a -> FromGeneric b -> FromGeneric a)
-> Functor FromGeneric
forall a b. a -> FromGeneric b -> FromGeneric a
forall a b. (a -> b) -> FromGeneric a -> FromGeneric b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> FromGeneric b -> FromGeneric a
$c<$ :: forall a b. a -> FromGeneric b -> FromGeneric a
fmap :: (a -> b) -> FromGeneric a -> FromGeneric b
$cfmap :: forall a b. (a -> b) -> FromGeneric a -> FromGeneric b
Functor
           , (forall x. FromGeneric a -> Rep (FromGeneric a) x)
-> (forall x. Rep (FromGeneric a) x -> FromGeneric a)
-> Generic (FromGeneric a)
forall x. Rep (FromGeneric a) x -> FromGeneric a
forall x. FromGeneric a -> Rep (FromGeneric a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (FromGeneric a) x -> FromGeneric a
forall a x. FromGeneric a -> Rep (FromGeneric a) x
$cto :: forall a x. Rep (FromGeneric a) x -> FromGeneric a
$cfrom :: forall a x. FromGeneric a -> Rep (FromGeneric a) x
Generic
           , (forall a. FromGeneric a -> Rep1 FromGeneric a)
-> (forall a. Rep1 FromGeneric a -> FromGeneric a)
-> Generic1 FromGeneric
forall a. Rep1 FromGeneric a -> FromGeneric a
forall a. FromGeneric a -> Rep1 FromGeneric a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cto1 :: forall a. Rep1 FromGeneric a -> FromGeneric a
$cfrom1 :: forall a. FromGeneric a -> Rep1 FromGeneric a
Generic1
           , Eq (FromGeneric a)
Eq (FromGeneric a)
-> (FromGeneric a -> FromGeneric a -> Ordering)
-> (FromGeneric a -> FromGeneric a -> Bool)
-> (FromGeneric a -> FromGeneric a -> Bool)
-> (FromGeneric a -> FromGeneric a -> Bool)
-> (FromGeneric a -> FromGeneric a -> Bool)
-> (FromGeneric a -> FromGeneric a -> FromGeneric a)
-> (FromGeneric a -> FromGeneric a -> FromGeneric a)
-> Ord (FromGeneric a)
FromGeneric a -> FromGeneric a -> Bool
FromGeneric a -> FromGeneric a -> Ordering
FromGeneric a -> FromGeneric a -> FromGeneric a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (FromGeneric a)
forall a. Ord a => FromGeneric a -> FromGeneric a -> Bool
forall a. Ord a => FromGeneric a -> FromGeneric a -> Ordering
forall a. Ord a => FromGeneric a -> FromGeneric a -> FromGeneric a
min :: FromGeneric a -> FromGeneric a -> FromGeneric a
$cmin :: forall a. Ord a => FromGeneric a -> FromGeneric a -> FromGeneric a
max :: FromGeneric a -> FromGeneric a -> FromGeneric a
$cmax :: forall a. Ord a => FromGeneric a -> FromGeneric a -> FromGeneric a
>= :: FromGeneric a -> FromGeneric a -> Bool
$c>= :: forall a. Ord a => FromGeneric a -> FromGeneric a -> Bool
> :: FromGeneric a -> FromGeneric a -> Bool
$c> :: forall a. Ord a => FromGeneric a -> FromGeneric a -> Bool
<= :: FromGeneric a -> FromGeneric a -> Bool
$c<= :: forall a. Ord a => FromGeneric a -> FromGeneric a -> Bool
< :: FromGeneric a -> FromGeneric a -> Bool
$c< :: forall a. Ord a => FromGeneric a -> FromGeneric a -> Bool
compare :: FromGeneric a -> FromGeneric a -> Ordering
$ccompare :: forall a. Ord a => FromGeneric a -> FromGeneric a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (FromGeneric a)
Ord
           , ReadPrec [FromGeneric a]
ReadPrec (FromGeneric a)
Int -> ReadS (FromGeneric a)
ReadS [FromGeneric a]
(Int -> ReadS (FromGeneric a))
-> ReadS [FromGeneric a]
-> ReadPrec (FromGeneric a)
-> ReadPrec [FromGeneric a]
-> Read (FromGeneric a)
forall a. Read a => ReadPrec [FromGeneric a]
forall a. Read a => ReadPrec (FromGeneric a)
forall a. Read a => Int -> ReadS (FromGeneric a)
forall a. Read a => ReadS [FromGeneric a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FromGeneric a]
$creadListPrec :: forall a. Read a => ReadPrec [FromGeneric a]
readPrec :: ReadPrec (FromGeneric a)
$creadPrec :: forall a. Read a => ReadPrec (FromGeneric a)
readList :: ReadS [FromGeneric a]
$creadList :: forall a. Read a => ReadS [FromGeneric a]
readsPrec :: Int -> ReadS (FromGeneric a)
$creadsPrec :: forall a. Read a => Int -> ReadS (FromGeneric a)
Read
           , Int -> FromGeneric a -> ShowS
[FromGeneric a] -> ShowS
FromGeneric a -> String
(Int -> FromGeneric a -> ShowS)
-> (FromGeneric a -> String)
-> ([FromGeneric a] -> ShowS)
-> Show (FromGeneric a)
forall a. Show a => Int -> FromGeneric a -> ShowS
forall a. Show a => [FromGeneric a] -> ShowS
forall a. Show a => FromGeneric a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FromGeneric a] -> ShowS
$cshowList :: forall a. Show a => [FromGeneric a] -> ShowS
show :: FromGeneric a -> String
$cshow :: forall a. Show a => FromGeneric a -> String
showsPrec :: Int -> FromGeneric a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> FromGeneric a -> ShowS
Show
           , Functor FromGeneric
Foldable FromGeneric
Functor FromGeneric
-> Foldable FromGeneric
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> FromGeneric a -> f (FromGeneric b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    FromGeneric (f a) -> f (FromGeneric a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> FromGeneric a -> m (FromGeneric b))
-> (forall (m :: * -> *) a.
    Monad m =>
    FromGeneric (m a) -> m (FromGeneric a))
-> Traversable FromGeneric
(a -> f b) -> FromGeneric a -> f (FromGeneric b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
FromGeneric (m a) -> m (FromGeneric a)
forall (f :: * -> *) a.
Applicative f =>
FromGeneric (f a) -> f (FromGeneric a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> FromGeneric a -> m (FromGeneric b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FromGeneric a -> f (FromGeneric b)
sequence :: FromGeneric (m a) -> m (FromGeneric a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
FromGeneric (m a) -> m (FromGeneric a)
mapM :: (a -> m b) -> FromGeneric a -> m (FromGeneric b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> FromGeneric a -> m (FromGeneric b)
sequenceA :: FromGeneric (f a) -> f (FromGeneric a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
FromGeneric (f a) -> f (FromGeneric a)
traverse :: (a -> f b) -> FromGeneric a -> f (FromGeneric b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FromGeneric a -> f (FromGeneric b)
$cp2Traversable :: Foldable FromGeneric
$cp1Traversable :: Functor FromGeneric
Traversable
           , Typeable
#if __GLASGOW_HASKELL__ >= 800
           , FromGeneric a -> Q Exp
FromGeneric a -> Q (TExp (FromGeneric a))
(FromGeneric a -> Q Exp)
-> (FromGeneric a -> Q (TExp (FromGeneric a)))
-> Lift (FromGeneric a)
forall a. Lift a => FromGeneric a -> Q Exp
forall a. Lift a => FromGeneric a -> Q (TExp (FromGeneric a))
forall t. (t -> Q Exp) -> (t -> Q (TExp t)) -> Lift t
liftTyped :: FromGeneric a -> Q (TExp (FromGeneric a))
$cliftTyped :: forall a. Lift a => FromGeneric a -> Q (TExp (FromGeneric a))
lift :: FromGeneric a -> Q Exp
$clift :: forall a. Lift a => FromGeneric a -> Q Exp
Lift
#endif
           )

-- | /Since: 3.7.4/
instance (Generic a, GTextShowB Zero (Rep a)) => TextShow (FromGeneric a) where
  showbPrec :: Int -> FromGeneric a -> Builder
showbPrec Int
p = Int -> a -> Builder
forall a.
(Generic a, GTextShowB Zero (Rep a)) =>
Int -> a -> Builder
genericShowbPrec Int
p (a -> Builder) -> (FromGeneric a -> a) -> FromGeneric a -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FromGeneric a -> a
forall a. FromGeneric a -> a
fromGeneric

-- | An adapter newtype, suitable for @DerivingVia@.
-- The 'TextShow1' instance for 'FromGeneric1' leverages a 'Generic1'-based
-- default. That is,
--
-- @
-- 'liftShowbPrec' sp sl p ('FromGeneric1' x) = 'genericLiftShowbPrec' sp sl p x
-- @
--
-- /Since: 3.7.4/
newtype FromGeneric1 f a = FromGeneric1 { FromGeneric1 f a -> f a
fromGeneric1 :: f a }
  deriving ( FromGeneric1 f a -> FromGeneric1 f a -> Bool
(FromGeneric1 f a -> FromGeneric1 f a -> Bool)
-> (FromGeneric1 f a -> FromGeneric1 f a -> Bool)
-> Eq (FromGeneric1 f a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (f :: k -> *) (a :: k).
Eq (f a) =>
FromGeneric1 f a -> FromGeneric1 f a -> Bool
/= :: FromGeneric1 f a -> FromGeneric1 f a -> Bool
$c/= :: forall k (f :: k -> *) (a :: k).
Eq (f a) =>
FromGeneric1 f a -> FromGeneric1 f a -> Bool
== :: FromGeneric1 f a -> FromGeneric1 f a -> Bool
$c== :: forall k (f :: k -> *) (a :: k).
Eq (f a) =>
FromGeneric1 f a -> FromGeneric1 f a -> Bool
Eq
           , Eq (FromGeneric1 f a)
Eq (FromGeneric1 f a)
-> (FromGeneric1 f a -> FromGeneric1 f a -> Ordering)
-> (FromGeneric1 f a -> FromGeneric1 f a -> Bool)
-> (FromGeneric1 f a -> FromGeneric1 f a -> Bool)
-> (FromGeneric1 f a -> FromGeneric1 f a -> Bool)
-> (FromGeneric1 f a -> FromGeneric1 f a -> Bool)
-> (FromGeneric1 f a -> FromGeneric1 f a -> FromGeneric1 f a)
-> (FromGeneric1 f a -> FromGeneric1 f a -> FromGeneric1 f a)
-> Ord (FromGeneric1 f a)
FromGeneric1 f a -> FromGeneric1 f a -> Bool
FromGeneric1 f a -> FromGeneric1 f a -> Ordering
FromGeneric1 f a -> FromGeneric1 f a -> FromGeneric1 f a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall k (f :: k -> *) (a :: k). Ord (f a) => Eq (FromGeneric1 f a)
forall k (f :: k -> *) (a :: k).
Ord (f a) =>
FromGeneric1 f a -> FromGeneric1 f a -> Bool
forall k (f :: k -> *) (a :: k).
Ord (f a) =>
FromGeneric1 f a -> FromGeneric1 f a -> Ordering
forall k (f :: k -> *) (a :: k).
Ord (f a) =>
FromGeneric1 f a -> FromGeneric1 f a -> FromGeneric1 f a
min :: FromGeneric1 f a -> FromGeneric1 f a -> FromGeneric1 f a
$cmin :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
FromGeneric1 f a -> FromGeneric1 f a -> FromGeneric1 f a
max :: FromGeneric1 f a -> FromGeneric1 f a -> FromGeneric1 f a
$cmax :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
FromGeneric1 f a -> FromGeneric1 f a -> FromGeneric1 f a
>= :: FromGeneric1 f a -> FromGeneric1 f a -> Bool
$c>= :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
FromGeneric1 f a -> FromGeneric1 f a -> Bool
> :: FromGeneric1 f a -> FromGeneric1 f a -> Bool
$c> :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
FromGeneric1 f a -> FromGeneric1 f a -> Bool
<= :: FromGeneric1 f a -> FromGeneric1 f a -> Bool
$c<= :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
FromGeneric1 f a -> FromGeneric1 f a -> Bool
< :: FromGeneric1 f a -> FromGeneric1 f a -> Bool
$c< :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
FromGeneric1 f a -> FromGeneric1 f a -> Bool
compare :: FromGeneric1 f a -> FromGeneric1 f a -> Ordering
$ccompare :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
FromGeneric1 f a -> FromGeneric1 f a -> Ordering
$cp1Ord :: forall k (f :: k -> *) (a :: k). Ord (f a) => Eq (FromGeneric1 f a)
Ord
           , ReadPrec [FromGeneric1 f a]
ReadPrec (FromGeneric1 f a)
Int -> ReadS (FromGeneric1 f a)
ReadS [FromGeneric1 f a]
(Int -> ReadS (FromGeneric1 f a))
-> ReadS [FromGeneric1 f a]
-> ReadPrec (FromGeneric1 f a)
-> ReadPrec [FromGeneric1 f a]
-> Read (FromGeneric1 f a)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadPrec [FromGeneric1 f a]
forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadPrec (FromGeneric1 f a)
forall k (f :: k -> *) (a :: k).
Read (f a) =>
Int -> ReadS (FromGeneric1 f a)
forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadS [FromGeneric1 f a]
readListPrec :: ReadPrec [FromGeneric1 f a]
$creadListPrec :: forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadPrec [FromGeneric1 f a]
readPrec :: ReadPrec (FromGeneric1 f a)
$creadPrec :: forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadPrec (FromGeneric1 f a)
readList :: ReadS [FromGeneric1 f a]
$creadList :: forall k (f :: k -> *) (a :: k).
Read (f a) =>
ReadS [FromGeneric1 f a]
readsPrec :: Int -> ReadS (FromGeneric1 f a)
$creadsPrec :: forall k (f :: k -> *) (a :: k).
Read (f a) =>
Int -> ReadS (FromGeneric1 f a)
Read
           , Int -> FromGeneric1 f a -> ShowS
[FromGeneric1 f a] -> ShowS
FromGeneric1 f a -> String
(Int -> FromGeneric1 f a -> ShowS)
-> (FromGeneric1 f a -> String)
-> ([FromGeneric1 f a] -> ShowS)
-> Show (FromGeneric1 f a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (f :: k -> *) (a :: k).
Show (f a) =>
Int -> FromGeneric1 f a -> ShowS
forall k (f :: k -> *) (a :: k).
Show (f a) =>
[FromGeneric1 f a] -> ShowS
forall k (f :: k -> *) (a :: k).
Show (f a) =>
FromGeneric1 f a -> String
showList :: [FromGeneric1 f a] -> ShowS
$cshowList :: forall k (f :: k -> *) (a :: k).
Show (f a) =>
[FromGeneric1 f a] -> ShowS
show :: FromGeneric1 f a -> String
$cshow :: forall k (f :: k -> *) (a :: k).
Show (f a) =>
FromGeneric1 f a -> String
showsPrec :: Int -> FromGeneric1 f a -> ShowS
$cshowsPrec :: forall k (f :: k -> *) (a :: k).
Show (f a) =>
Int -> FromGeneric1 f a -> ShowS
Show
           , (forall x. FromGeneric1 f a -> Rep (FromGeneric1 f a) x)
-> (forall x. Rep (FromGeneric1 f a) x -> FromGeneric1 f a)
-> Generic (FromGeneric1 f a)
forall x. Rep (FromGeneric1 f a) x -> FromGeneric1 f a
forall x. FromGeneric1 f a -> Rep (FromGeneric1 f a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k (f :: k -> *) (a :: k) x.
Rep (FromGeneric1 f a) x -> FromGeneric1 f a
forall k (f :: k -> *) (a :: k) x.
FromGeneric1 f a -> Rep (FromGeneric1 f a) x
$cto :: forall k (f :: k -> *) (a :: k) x.
Rep (FromGeneric1 f a) x -> FromGeneric1 f a
$cfrom :: forall k (f :: k -> *) (a :: k) x.
FromGeneric1 f a -> Rep (FromGeneric1 f a) x
Generic
#if defined(__LANGUAGE_DERIVE_GENERIC1__)
           , Generic1
#endif
#if __GLASGOW_HASKELL__ >= 800
           , FromGeneric1 f a -> Q Exp
FromGeneric1 f a -> Q (TExp (FromGeneric1 f a))
(FromGeneric1 f a -> Q Exp)
-> (FromGeneric1 f a -> Q (TExp (FromGeneric1 f a)))
-> Lift (FromGeneric1 f a)
forall k (f :: k -> *) (a :: k).
Lift (f a) =>
FromGeneric1 f a -> Q Exp
forall k (f :: k -> *) (a :: k).
Lift (f a) =>
FromGeneric1 f a -> Q (TExp (FromGeneric1 f a))
forall t. (t -> Q Exp) -> (t -> Q (TExp t)) -> Lift t
liftTyped :: FromGeneric1 f a -> Q (TExp (FromGeneric1 f a))
$cliftTyped :: forall k (f :: k -> *) (a :: k).
Lift (f a) =>
FromGeneric1 f a -> Q (TExp (FromGeneric1 f a))
lift :: FromGeneric1 f a -> Q Exp
$clift :: forall k (f :: k -> *) (a :: k).
Lift (f a) =>
FromGeneric1 f a -> Q Exp
Lift
#endif
           )

deriving instance Foldable    f => Foldable    (FromGeneric1 f)
deriving instance Functor     f => Functor     (FromGeneric1 f)
deriving instance Traversable f => Traversable (FromGeneric1 f)
deriving instance Typeable FromGeneric1
deriving instance ( Data (f a), Typeable f, Typeable a
                  ) => Data (FromGeneric1 f (a :: *))

-- | /Since: 3.7.4/
instance (Generic1 f, GTextShowB One (Rep1 f)) => TextShow1 (FromGeneric1 f) where
  liftShowbPrec :: (Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> FromGeneric1 f a -> Builder
liftShowbPrec Int -> a -> Builder
sp [a] -> Builder
sl Int
p = (Int -> a -> Builder) -> ([a] -> Builder) -> Int -> f a -> Builder
forall (f :: * -> *) a.
(Generic1 f, GTextShowB One (Rep1 f)) =>
(Int -> a -> Builder) -> ([a] -> Builder) -> Int -> f a -> Builder
genericLiftShowbPrec Int -> a -> Builder
sp [a] -> Builder
sl Int
p (f a -> Builder)
-> (FromGeneric1 f a -> f a) -> FromGeneric1 f a -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FromGeneric1 f a -> f a
forall k (f :: k -> *) (a :: k). FromGeneric1 f a -> f a
fromGeneric1

-- | A 'Generic' implementation of 'showt'.
--
-- /Since: 2/
genericShowt :: (Generic a, GTextShowT Zero (Rep a)) => a -> TS.Text
genericShowt :: a -> Text
genericShowt = Int -> a -> Text
forall a. (Generic a, GTextShowT Zero (Rep a)) => Int -> a -> Text
genericShowtPrec Int
0

-- | A 'Generic' implementation of 'showtl'.
--
-- /Since: 2/
genericShowtl :: (Generic a, GTextShowTL Zero (Rep a)) => a -> TL.Text
genericShowtl :: a -> Text
genericShowtl = Int -> a -> Text
forall a. (Generic a, GTextShowTL Zero (Rep a)) => Int -> a -> Text
genericShowtlPrec Int
0

-- | A 'Generic' implementation of 'showPrect'.
--
-- /Since: 2/
genericShowtPrec :: (Generic a, GTextShowT Zero (Rep a)) => Int -> a -> TS.Text
genericShowtPrec :: Int -> a -> Text
genericShowtPrec Int
p = ShowFunsT Zero Any -> Int -> Rep a Any -> Text
forall arity (f :: * -> *) a.
GTextShowT arity f =>
ShowFunsT arity a -> Int -> f a -> Text
gShowtPrec ShowFunsT Zero Any
forall a. ShowFunsT Zero a
NoShowFunsT Int
p (Rep a Any -> Text) -> (a -> Rep a Any) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Rep a Any
forall a x. Generic a => a -> Rep a x
from

-- | A 'Generic' implementation of 'showtlPrec'.
--
-- /Since: 2/
genericShowtlPrec :: (Generic a, GTextShowTL Zero (Rep a)) => Int -> a -> TL.Text
genericShowtlPrec :: Int -> a -> Text
genericShowtlPrec Int
p = ShowFunsTL Zero Any -> Int -> Rep a Any -> Text
forall arity (f :: * -> *) a.
GTextShowTL arity f =>
ShowFunsTL arity a -> Int -> f a -> Text
gShowtlPrec ShowFunsTL Zero Any
forall a. ShowFunsTL Zero a
NoShowFunsTL Int
p (Rep a Any -> Text) -> (a -> Rep a Any) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Rep a Any
forall a x. Generic a => a -> Rep a x
from

-- | A 'Generic' implementation of 'showtList'.
--
-- /Since: 2/
genericShowtList :: (Generic a, GTextShowT Zero (Rep a)) => [a] -> TS.Text
genericShowtList :: [a] -> Text
genericShowtList = (a -> Text) -> [a] -> Text
forall a. (a -> Text) -> [a] -> Text
showtListWith a -> Text
forall a. (Generic a, GTextShowT Zero (Rep a)) => a -> Text
genericShowt

-- | A 'Generic' implementation of 'showtlList'.
--
-- /Since: 2/
genericShowtlList :: (Generic a, GTextShowTL Zero (Rep a)) => [a] -> TL.Text
genericShowtlList :: [a] -> Text
genericShowtlList = (a -> Text) -> [a] -> Text
forall a. (a -> Text) -> [a] -> Text
showtlListWith a -> Text
forall a. (Generic a, GTextShowTL Zero (Rep a)) => a -> Text
genericShowtl

-- | A 'Generic' implementation of 'showb'.
--
-- /Since: 2/
genericShowb :: (Generic a, GTextShowB Zero (Rep a)) => a -> Builder
genericShowb :: a -> Builder
genericShowb = Int -> a -> Builder
forall a.
(Generic a, GTextShowB Zero (Rep a)) =>
Int -> a -> Builder
genericShowbPrec Int
0

-- | A 'Generic' implementation of 'showbPrec'.
--
-- /Since: 2/
genericShowbPrec :: (Generic a, GTextShowB Zero (Rep a)) => Int -> a -> Builder
genericShowbPrec :: Int -> a -> Builder
genericShowbPrec Int
p = ShowFunsB Zero Any -> Int -> Rep a Any -> Builder
forall arity (f :: * -> *) a.
GTextShowB arity f =>
ShowFunsB arity a -> Int -> f a -> Builder
gShowbPrec ShowFunsB Zero Any
forall a. ShowFunsB Zero a
NoShowFunsB Int
p (Rep a Any -> Builder) -> (a -> Rep a Any) -> a -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Rep a Any
forall a x. Generic a => a -> Rep a x
from

-- | A 'Generic' implementation of 'showbList'.
--
-- /Since: 2/
genericShowbList :: (Generic a, GTextShowB Zero (Rep a)) => [a] -> Builder
genericShowbList :: [a] -> Builder
genericShowbList = (a -> Builder) -> [a] -> Builder
forall a. (a -> Builder) -> [a] -> Builder
showbListWith a -> Builder
forall a. (Generic a, GTextShowB Zero (Rep a)) => a -> Builder
genericShowb

-- | A 'Generic' implementation of 'printT'.
--
-- /Since: 2/
genericPrintT :: (Generic a, GTextShowT Zero (Rep a)) => a -> IO ()
genericPrintT :: a -> IO ()
genericPrintT = Text -> IO ()
TS.putStrLn (Text -> IO ()) -> (a -> Text) -> a -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Text
forall a. (Generic a, GTextShowT Zero (Rep a)) => a -> Text
genericShowt

-- | A 'Generic' implementation of 'printTL'.
--
-- /Since: 2/
genericPrintTL :: (Generic a, GTextShowTL Zero (Rep a)) => a -> IO ()
genericPrintTL :: a -> IO ()
genericPrintTL = Text -> IO ()
TL.putStrLn (Text -> IO ()) -> (a -> Text) -> a -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Text
forall a. (Generic a, GTextShowTL Zero (Rep a)) => a -> Text
genericShowtl

-- | A 'Generic' implementation of 'hPrintT'.
--
-- /Since: 2/
genericHPrintT :: (Generic a, GTextShowT Zero (Rep a)) => Handle -> a -> IO ()
genericHPrintT :: Handle -> a -> IO ()
genericHPrintT Handle
h = Handle -> Text -> IO ()
TS.hPutStrLn Handle
h (Text -> IO ()) -> (a -> Text) -> a -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Text
forall a. (Generic a, GTextShowT Zero (Rep a)) => a -> Text
genericShowt

-- | A 'Generic' implementation of 'hPrintTL'.
--
-- /Since: 2/
genericHPrintTL :: (Generic a, GTextShowTL Zero (Rep a)) => Handle -> a -> IO ()
genericHPrintTL :: Handle -> a -> IO ()
genericHPrintTL Handle
h = Handle -> Text -> IO ()
TL.hPutStrLn Handle
h (Text -> IO ()) -> (a -> Text) -> a -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Text
forall a. (Generic a, GTextShowTL Zero (Rep a)) => a -> Text
genericShowtl

-- | A 'Generic1' implementation of 'genericLiftShowbPrec'.
--
-- /Since: 2/
genericLiftShowbPrec :: (Generic1 f, GTextShowB One (Rep1 f))
                     => (Int -> a -> Builder) -> ([a] -> Builder)
                     -> Int -> f a -> Builder
genericLiftShowbPrec :: (Int -> a -> Builder) -> ([a] -> Builder) -> Int -> f a -> Builder
genericLiftShowbPrec Int -> a -> Builder
sp [a] -> Builder
sl Int
p = ShowFunsB One a -> Int -> Rep1 f a -> Builder
forall arity (f :: * -> *) a.
GTextShowB arity f =>
ShowFunsB arity a -> Int -> f a -> Builder
gShowbPrec ((Int -> a -> Builder) -> ([a] -> Builder) -> ShowFunsB One a
forall a.
(Int -> a -> Builder) -> ([a] -> Builder) -> ShowFunsB One a
Show1FunsB Int -> a -> Builder
sp [a] -> Builder
sl) Int
p (Rep1 f a -> Builder) -> (f a -> Rep1 f a) -> f a -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> Rep1 f a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1

-- | A 'Generic'/'Generic1' implementation of 'showbPrec1'.
--
-- /Since: 2/
genericShowbPrec1 :: ( Generic a, Generic1 f
                     , GTextShowB Zero (Rep  a)
                     , GTextShowB One  (Rep1 f)
                     )
                  => Int -> f a -> Builder
genericShowbPrec1 :: Int -> f a -> Builder
genericShowbPrec1 = (Int -> a -> Builder) -> ([a] -> Builder) -> Int -> f a -> Builder
forall (f :: * -> *) a.
(Generic1 f, GTextShowB One (Rep1 f)) =>
(Int -> a -> Builder) -> ([a] -> Builder) -> Int -> f a -> Builder
genericLiftShowbPrec Int -> a -> Builder
forall a.
(Generic a, GTextShowB Zero (Rep a)) =>
Int -> a -> Builder
genericShowbPrec [a] -> Builder
forall a. (Generic a, GTextShowB Zero (Rep a)) => [a] -> Builder
genericShowbList

-------------------------------------------------------------------------------

-- | Whether a constructor is a record ('Rec'), a tuple ('Tup'), is prefix ('Pref'),
-- or infix ('Inf').
--
-- /Since: 2/
data ConType = Rec | Tup | Pref | Inf String
  deriving ( Typeable ConType
DataType
Constr
Typeable ConType
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ConType -> c ConType)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ConType)
-> (ConType -> Constr)
-> (ConType -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ConType))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ConType))
-> ((forall b. Data b => b -> b) -> ConType -> ConType)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ConType -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ConType -> r)
-> (forall u. (forall d. Data d => d -> u) -> ConType -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> ConType -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ConType -> m ConType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ConType -> m ConType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ConType -> m ConType)
-> Data ConType
ConType -> DataType
ConType -> Constr
(forall b. Data b => b -> b) -> ConType -> ConType
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConType -> c ConType
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConType
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ConType -> u
forall u. (forall d. Data d => d -> u) -> ConType -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConType -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConType -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConType -> m ConType
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConType -> m ConType
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConType
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConType -> c ConType
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ConType)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ConType)
$cInf :: Constr
$cPref :: Constr
$cTup :: Constr
$cRec :: Constr
$tConType :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> ConType -> m ConType
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConType -> m ConType
gmapMp :: (forall d. Data d => d -> m d) -> ConType -> m ConType
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConType -> m ConType
gmapM :: (forall d. Data d => d -> m d) -> ConType -> m ConType
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConType -> m ConType
gmapQi :: Int -> (forall d. Data d => d -> u) -> ConType -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ConType -> u
gmapQ :: (forall d. Data d => d -> u) -> ConType -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ConType -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConType -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConType -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConType -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConType -> r
gmapT :: (forall b. Data b => b -> b) -> ConType -> ConType
$cgmapT :: (forall b. Data b => b -> b) -> ConType -> ConType
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ConType)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ConType)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c ConType)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ConType)
dataTypeOf :: ConType -> DataType
$cdataTypeOf :: ConType -> DataType
toConstr :: ConType -> Constr
$ctoConstr :: ConType -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConType
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConType
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConType -> c ConType
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConType -> c ConType
$cp1Data :: Typeable ConType
Data
           , ConType -> ConType -> Bool
(ConType -> ConType -> Bool)
-> (ConType -> ConType -> Bool) -> Eq ConType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConType -> ConType -> Bool
$c/= :: ConType -> ConType -> Bool
== :: ConType -> ConType -> Bool
$c== :: ConType -> ConType -> Bool
Eq
           , (forall x. ConType -> Rep ConType x)
-> (forall x. Rep ConType x -> ConType) -> Generic ConType
forall x. Rep ConType x -> ConType
forall x. ConType -> Rep ConType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConType x -> ConType
$cfrom :: forall x. ConType -> Rep ConType x
Generic
           , Eq ConType
Eq ConType
-> (ConType -> ConType -> Ordering)
-> (ConType -> ConType -> Bool)
-> (ConType -> ConType -> Bool)
-> (ConType -> ConType -> Bool)
-> (ConType -> ConType -> Bool)
-> (ConType -> ConType -> ConType)
-> (ConType -> ConType -> ConType)
-> Ord ConType
ConType -> ConType -> Bool
ConType -> ConType -> Ordering
ConType -> ConType -> ConType
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ConType -> ConType -> ConType
$cmin :: ConType -> ConType -> ConType
max :: ConType -> ConType -> ConType
$cmax :: ConType -> ConType -> ConType
>= :: ConType -> ConType -> Bool
$c>= :: ConType -> ConType -> Bool
> :: ConType -> ConType -> Bool
$c> :: ConType -> ConType -> Bool
<= :: ConType -> ConType -> Bool
$c<= :: ConType -> ConType -> Bool
< :: ConType -> ConType -> Bool
$c< :: ConType -> ConType -> Bool
compare :: ConType -> ConType -> Ordering
$ccompare :: ConType -> ConType -> Ordering
$cp1Ord :: Eq ConType
Ord
           , ReadPrec [ConType]
ReadPrec ConType
Int -> ReadS ConType
ReadS [ConType]
(Int -> ReadS ConType)
-> ReadS [ConType]
-> ReadPrec ConType
-> ReadPrec [ConType]
-> Read ConType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ConType]
$creadListPrec :: ReadPrec [ConType]
readPrec :: ReadPrec ConType
$creadPrec :: ReadPrec ConType
readList :: ReadS [ConType]
$creadList :: ReadS [ConType]
readsPrec :: Int -> ReadS ConType
$creadsPrec :: Int -> ReadS ConType
Read
           , Int -> ConType -> ShowS
[ConType] -> ShowS
ConType -> String
(Int -> ConType -> ShowS)
-> (ConType -> String) -> ([ConType] -> ShowS) -> Show ConType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConType] -> ShowS
$cshowList :: [ConType] -> ShowS
show :: ConType -> String
$cshow :: ConType -> String
showsPrec :: Int -> ConType -> ShowS
$cshowsPrec :: Int -> ConType -> ShowS
Show
           , Typeable
#if __GLASGOW_HASKELL__ >= 800
           , ConType -> Q Exp
ConType -> Q (TExp ConType)
(ConType -> Q Exp) -> (ConType -> Q (TExp ConType)) -> Lift ConType
forall t. (t -> Q Exp) -> (t -> Q (TExp t)) -> Lift t
liftTyped :: ConType -> Q (TExp ConType)
$cliftTyped :: ConType -> Q (TExp ConType)
lift :: ConType -> Q Exp
$clift :: ConType -> Q Exp
Lift
#endif
           )

-- | A type-level indicator that 'TextShow' is being derived generically.
--
-- /Since: 3.2/
data Zero

-- | A type-level indicator that 'TextShow1' is being derived generically.
--
-- /Since: 3.2/
data One

{-
I'm not particularly proud of the code below. The issue is that we need to be able to
generically work over Builders, strict Text, and lazy Text. We could just work
generically over Builders only and then convert to Text after the fact, but that results
in a drastic slowdown for certain datatypes (see GH-21 for an example).

For the most part, the shared functionality could be abstracted with a subclass of
Monoid that supports fromString, fromChar, etc. But there's a very small chance that
the code below is ever going to inline properly, and the runtime cost of all those
dictinary lookups is likely to be as bad as converting to Text at the end, if not worse.

Therefore, I perform some ugly CPP hackery to copy-paste the generic functionality three
times, once for each Text/Builder variant. At some point, I should replace this with TH.
See #33.
-}

#if __GLASGOW_HASKELL__ >= 711
#define HASH_FUNS(text_type,one_hash,two_hash,hash_prec,from_char,from_string) \
one_hash, two_hash :: text_type; \
hash_prec :: Int -> Int;         \
one_hash  = from_char '#';       \
two_hash  = from_string "##";    \
hash_prec = const 0
#else
#define HASH_FUNS(text_type,one_hash,two_hash,hash_prec,from_char,from_string) \
one_hash, two_hash :: text_type; \
hash_prec :: Int -> Int;         \
one_hash  = mempty;              \
two_hash  = mempty;              \
hash_prec = id
#endif

#define GTEXT_SHOW(text_type,show_funs,no_show_funs,show1_funs,one_hash,two_hash,hash_prec,gtext_show,gshow_prec,gtext_show_con,gshow_prec_con,show_prec,lift_show_prec,show_space,show_paren,show_list_with,from_char,from_string) \
{- | A 'show_funs' value either stores nothing (for 'TextShow') or it stores            \
the two function arguments that show occurrences of the type parameter (for             \
'TextShow1').                                                                           \
                                                                                        \
/Since: 3.4/                                                                            \
-};                                                                                     \
data show_funs arity a where {                                                          \
    no_show_funs :: show_funs Zero a                                                    \
  ; show1_funs   :: (Int -> a -> text_type) -> ([a] -> text_type) -> show_funs One a    \
 } deriving Typeable;                                                                   \
                                                                                        \
instance Contravariant (show_funs arity) where {                                        \
    contramap _ no_show_funs       = no_show_funs                                       \
  ; contramap f (show1_funs sp sl) = show1_funs (\p -> sp p . f) (sl . map f)           \
 };                                                                                     \
                                                                                        \
{- | Class of generic representation types that can be converted to                     \
a 'text_type'. The @arity@ type variable indicates which type class is                  \
used. @'gtext_show' 'Zero'@ indicates 'TextShow' behavior, and                          \
@'gtext_show' 'One'@ indicates 'TextShow1' behavior.                                    \
                                                                                        \
/Since: 3.4/                                                                            \
-};                                                                                     \
class gtext_show arity f where {                                                        \
    {- | This is used as the default generic implementation of 'show_prec' (if the      \
    @arity@ is 'Zero') or 'lift_show_prec' (if the @arity@ is 'One').                   \
    -}                                                                                  \
  ; gshow_prec :: show_funs arity a -> Int -> f a -> text_type                          \
 };                                                                                     \
                                                                                        \
deriving instance Typeable gtext_show;                                                  \
                                                                                        \
instance gtext_show arity f => gtext_show arity (D1 d f) where {                        \
    gshow_prec sfs p (M1 x) = gshow_prec sfs p x                                        \
 };                                                                                     \
                                                                                        \
instance gtext_show arity V1 where {                                                    \
    gshow_prec _ _ x = case x of {}                                                     \
 };                                                                                     \
                                                                                        \
instance (gtext_show arity f, gtext_show arity g) => gtext_show arity (f :+: g) where { \
    gshow_prec sfs p (L1 x) = gshow_prec sfs p x                                        \
  ; gshow_prec sfs p (R1 x) = gshow_prec sfs p x                                        \
 };                                                                                     \
                                                                                        \
instance (Constructor c, gtext_show_con arity f, IsNullary f)                           \
      => gtext_show arity (C1 c f) where {                                              \
    gshow_prec sfs p c@(M1 x) = case fixity of {                                        \
        Prefix -> show_paren ( p > appPrec                                              \
                               && not (isNullary x || conIsTuple c)                     \
                             ) $                                                        \
               (if conIsTuple c                                                         \
                   then mempty                                                          \
                   else let cn = conName c                                              \
                        in show_paren (isInfixDataCon cn) $ from_string cn)             \
            <> (if isNullary x || conIsTuple c                                          \
                   then mempty                                                          \
                   else from_char ' ')                                                  \
            <> showbBraces t (gshow_prec_con t sfs appPrec1 x)                          \
      ; Infix _ m -> show_paren (p > m) $ gshow_prec_con t sfs (m+1) x                  \
      }                                                                                 \
    where {                                                                             \
        fixity :: Fixity                                                                \
      ; fixity = conFixity c                                                            \
                                                                                        \
      ; t :: ConType                                                                    \
      ; t = if conIsRecord c                                                            \
            then Rec                                                                    \
            else case conIsTuple c of {                                                 \
                True  -> Tup                                                            \
              ; False -> case fixity of {                                               \
                    Prefix    -> Pref                                                   \
                  ; Infix _ _ -> Inf $ conName c                                        \
                };                                                                      \
              }                                                                         \
                                                                                        \
      ; showbBraces :: ConType -> text_type -> text_type                                \
      ; showbBraces Rec     b = from_char '{' <> b <> from_char '}'                     \
      ; showbBraces Tup     b = from_char '(' <> b <> from_char ')'                     \
      ; showbBraces Pref    b = b                                                       \
      ; showbBraces (Inf _) b = b                                                       \
                                                                                        \
      ; conIsTuple :: C1 c f p -> Bool                                                  \
      ; conIsTuple = isTupleString . conName                                            \
     };                                                                                 \
 };                                                                                     \
                                                                                        \
{- | Class of generic representation types for which the 'ConType' has been             \
determined. The @arity@ type variable indicates which type class is                     \
used. @'gtext_show_con' 'Zero'@ indicates 'TextShow' behavior, and                      \
@'gtext_show_con' 'One'@ indicates 'TextShow1' behavior.                                \
-};                                                                                     \
class gtext_show_con arity f where {                                                    \
    {- | Convert value of a specific 'ConType' to a 'text_type' with the given          \
    precedence.                                                                         \
    -}                                                                                  \
  ; gshow_prec_con :: ConType -> show_funs arity a -> Int -> f a -> text_type           \
 };                                                                                     \
                                                                                        \
deriving instance Typeable gtext_show_con;                                              \
                                                                                        \
instance gtext_show_con arity U1 where {                                                \
    gshow_prec_con _ _ _ U1 = mempty                                                    \
 };                                                                                     \
                                                                                        \
instance gtext_show_con One Par1 where {                                                \
    gshow_prec_con _ (show1_funs sp _) p (Par1 x) = sp p x                              \
 };                                                                                     \
                                                                                        \
instance TextShow c => gtext_show_con arity (K1 i c) where {                            \
    gshow_prec_con _ _ p (K1 x) = show_prec p x                                         \
 };                                                                                     \
                                                                                        \
instance TextShow1 f => gtext_show_con One (Rec1 f) where {                             \
    gshow_prec_con _ (show1_funs sp sl) p (Rec1 x) = lift_show_prec sp sl p x           \
 };                                                                                     \
                                                                                        \
instance (Selector s, gtext_show_con arity f) => gtext_show_con arity (S1 s f) where {  \
    gshow_prec_con t sfs p sel@(M1 x)                                                   \
      | selName sel == "" = gshow_prec_con t sfs p x                                    \
      | otherwise         = infixRec                                                    \
                            <> " = "                                                    \
                            <> gshow_prec_con t sfs 0 x                                 \
      where {                                                                           \
        infixRec :: text_type                                                           \
      ; infixRec | isSymVar selectorName                                                \
                 = from_char '(' <> from_string selectorName <> from_char ')'           \
                 | otherwise                                                            \
                 = from_string selectorName                                             \
                                                                                        \
      ; selectorName :: String                                                          \
      ; selectorName = selName sel                                                      \
      }                                                                                 \
 };                                                                                     \
                                                                                        \
instance (gtext_show_con arity f, gtext_show_con arity g)                               \
      => gtext_show_con arity (f :*: g) where {                                         \
    gshow_prec_con t@Rec sfs _ (a :*: b) =                                              \
           gshow_prec_con t sfs 0 a                                                     \
        <> ", "                                                                         \
        <> gshow_prec_con t sfs 0 b                                                     \
  ; gshow_prec_con t@(Inf o) sfs p (a :*: b) =                                          \
           gshow_prec_con t sfs p a                                                     \
        <> show_space                                                                   \
        <> infixOp                                                                      \
        <> show_space                                                                   \
        <> gshow_prec_con t sfs p b                                                     \
      where {                                                                           \
        infixOp :: text_type                                                            \
      ; infixOp = if isInfixDataCon o                                                   \
                     then from_string o                                                 \
                     else from_char '`' <> from_string o <> from_char '`'               \
      }                                                                                 \
  ; gshow_prec_con t@Tup sfs _ (a :*: b) =                                              \
           gshow_prec_con t sfs 0 a                                                     \
        <> from_char ','                                                                \
        <> gshow_prec_con t sfs 0 b                                                     \
  ; gshow_prec_con t@Pref sfs p (a :*: b) =                                             \
           gshow_prec_con t sfs p a                                                     \
        <> show_space                                                                   \
        <> gshow_prec_con t sfs p b                                                     \
 };                                                                                     \
                                                                                        \
instance (TextShow1 f, gtext_show_con One g) => gtext_show_con One (f :.: g) where {    \
    gshow_prec_con t sfs p (Comp1 x) =                                                  \
      let gspc = gshow_prec_con t sfs                                                   \
      in lift_show_prec gspc (show_list_with (gspc 0)) p x                              \
 };                                                                                     \
                                                                                        \
instance gtext_show_con arity UChar where {                                             \
    gshow_prec_con _ _ p (UChar c)   = show_prec (hash_prec p) (C# c) <> one_hash       \
 };                                                                                     \
                                                                                        \
instance gtext_show_con arity UDouble where {                                           \
    gshow_prec_con _ _ p (UDouble d) = show_prec (hash_prec p) (D# d) <> two_hash       \
 };                                                                                     \
                                                                                        \
instance gtext_show_con arity UFloat where {                                            \
    gshow_prec_con _ _ p (UFloat f)  = show_prec (hash_prec p) (F# f) <> one_hash       \
 };                                                                                     \
                                                                                        \
instance gtext_show_con arity UInt where {                                              \
    gshow_prec_con _ _ p (UInt i)    = show_prec (hash_prec p) (I# i) <> one_hash       \
 };                                                                                     \
                                                                                        \
instance gtext_show_con arity UWord where {                                             \
    gshow_prec_con _ _ p (UWord w)   = show_prec (hash_prec p) (W# w) <> two_hash       \
 };                                                                                     \
                                                                                        \
HASH_FUNS(text_type,one_hash,two_hash,hash_prec,from_char,from_string);

GTEXT_SHOW(Builder,ShowFunsB,NoShowFunsB,Show1FunsB,oneHashB,twoHashB,hashPrecB,GTextShowB,gShowbPrec,GTextShowConB,gShowbPrecCon,showbPrec,liftShowbPrec,showbSpace,showbParen,showbListWith,TB.singleton,TB.fromString)
GTEXT_SHOW(TS.Text,ShowFunsT,NoShowFunsT,Show1FunsT,oneHashT,twoHashT,hashPrecT,GTextShowT,gShowtPrec,GTextShowConT,gShowtPrecCon,showtPrec,liftShowtPrec,showtSpace,showtParen,showtListWith,TS.singleton,TS.pack)
GTEXT_SHOW(TL.Text,ShowFunsTL,NoShowFunsTL,Show1FunsTL,oneHashTL,twoHashTL,hashPrecTL,GTextShowTL,gShowtlPrec,GTextShowConTL,gShowtlPrecCon,showtlPrec,liftShowtlPrec,showtlSpace,showtlParen,showtlListWith,TL.singleton,TL.pack)

-- | Class of generic representation types that represent a constructor with
-- zero or more fields.
class IsNullary f where
    -- Returns 'True' if the constructor has no fields.
    isNullary :: f a -> Bool

instance IsNullary U1 where
    isNullary :: U1 a -> Bool
isNullary U1 a
_ = Bool
True

instance IsNullary Par1 where
    isNullary :: Par1 a -> Bool
isNullary Par1 a
_ = Bool
False

instance IsNullary (K1 i c) where
    isNullary :: K1 i c a -> Bool
isNullary K1 i c a
_ = Bool
False

instance IsNullary f => IsNullary (S1 s f) where
    isNullary :: S1 s f a -> Bool
isNullary (M1 f a
x) = f a -> Bool
forall k (f :: k -> *) (a :: k). IsNullary f => f a -> Bool
isNullary f a
x

instance IsNullary (Rec1 f) where
    isNullary :: Rec1 f a -> Bool
isNullary Rec1 f a
_ = Bool
False

instance IsNullary (f :*: g) where
    isNullary :: (:*:) f g a -> Bool
isNullary (:*:) f g a
_ = Bool
False

instance IsNullary (f :.: g) where
    isNullary :: (:.:) f g a -> Bool
isNullary (:.:) f g a
_ = Bool
False

instance IsNullary UChar where
    isNullary :: UChar a -> Bool
isNullary UChar a
_ = Bool
False

instance IsNullary UDouble where
    isNullary :: UDouble a -> Bool
isNullary UDouble a
_ = Bool
False

instance IsNullary UFloat where
    isNullary :: UFloat a -> Bool
isNullary UFloat a
_ = Bool
False

instance IsNullary UInt where
    isNullary :: UInt a -> Bool
isNullary UInt a
_ = Bool
False

instance IsNullary UWord where
    isNullary :: UWord a -> Bool
isNullary UWord a
_ = Bool
False

-------------------------------------------------------------------------------

$(deriveTextShow ''ConType)

#if __GLASGOW_HASKELL__ < 800
$(deriveLift ''ConType)
$(deriveLift ''FromGeneric)

instance Lift (f a) => Lift (FromGeneric1 f a) where
    lift = $(makeLift ''FromGeneric1)
#endif

#if !defined(__LANGUAGE_DERIVE_GENERIC1__)
$(Generics.deriveMeta           ''FromGeneric1)
$(Generics.deriveRepresentable1 ''FromGeneric1)
#endif