{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeSynonymInstances #-}

#if __GLASGOW_HASKELL__ >= 701
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE Trustworthy #-}
#endif

#if __GLASGOW_HASKELL__ >= 708
{-# LANGUAGE EmptyCase #-}
#endif

module Generics.Deriving.Show (
  -- * Generic show class
    GShow(..)

  -- * Default definition
  , gshowsPrecdefault

  -- * Internal show class
  , GShow'(..)

  ) where

import           Control.Applicative (Const, ZipList)

import           Data.Char (GeneralCategory)
import           Data.Int
import           Data.Monoid (All, Any, Dual, Product, Sum)
import qualified Data.Monoid as Monoid (First, Last)
import           Data.Version (Version)
import           Data.Word

import           Foreign.C.Types
import           Foreign.ForeignPtr (ForeignPtr)
import           Foreign.Ptr

import           Generics.Deriving.Base

import           GHC.Exts hiding (Any)

import           System.Exit (ExitCode)
import           System.IO (BufferMode, Handle, HandlePosn, IOMode, SeekMode)
import           System.IO.Error (IOErrorType)
import           System.Posix.Types

#if MIN_VERSION_base(4,4,0)
import           Data.Complex (Complex)
#endif

#if MIN_VERSION_base(4,7,0)
import           Data.Proxy (Proxy)
#endif

#if MIN_VERSION_base(4,8,0)
import           Data.Functor.Identity (Identity)
import           Data.Monoid (Alt)
import           Data.Void (Void)
import           Numeric.Natural (Natural)
#endif

#if MIN_VERSION_base(4,9,0)
import           Data.List.NonEmpty (NonEmpty)
import qualified Data.Semigroup as Semigroup (First, Last)
import           Data.Semigroup (Arg, Max, Min, WrappedMonoid)
#endif

--------------------------------------------------------------------------------
-- Generic show
--------------------------------------------------------------------------------

intersperse :: a -> [a] -> [a]
intersperse :: a -> [a] -> [a]
intersperse a
_ []    = []
intersperse a
_ [a
h]   = [a
h]
intersperse a
x (a
h:[a]
t) = a
h a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: (a -> [a] -> [a]
forall a. a -> [a] -> [a]
intersperse a
x [a]
t)

appPrec :: Int
appPrec :: Int
appPrec = Int
2

data Type = Rec | Tup | Pref | Inf String

class GShow' f where
  gshowsPrec' :: Type -> Int -> f a -> ShowS
  isNullary   :: f a -> Bool
  isNullary = [Char] -> f a -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"generic show (isNullary): unnecessary case"

instance GShow' V1 where
  gshowsPrec' :: Type -> Int -> V1 a -> ShowS
gshowsPrec' Type
_ Int
_ V1 a
x = case V1 a
x of
#if __GLASGOW_HASKELL__ >= 708
                        {}
#else
                        !_ -> error "Void gshowsPrec"
#endif

instance GShow' U1 where
  gshowsPrec' :: Type -> Int -> U1 a -> ShowS
gshowsPrec' Type
_ Int
_ U1 a
U1 = ShowS
forall a. a -> a
id
  isNullary :: U1 a -> Bool
isNullary U1 a
_ = Bool
True

instance (GShow c) => GShow' (K1 i c) where
  gshowsPrec' :: Type -> Int -> K1 i c a -> ShowS
gshowsPrec' Type
_ Int
n (K1 c
a) = Int -> c -> ShowS
forall a. GShow a => Int -> a -> ShowS
gshowsPrec Int
n c
a
  isNullary :: K1 i c a -> Bool
isNullary K1 i c a
_ = Bool
False

-- No instances for P or Rec because gshow is only applicable to types of kind *

instance (GShow' a, Constructor c) => GShow' (M1 C c a) where
  gshowsPrec' :: Type -> Int -> M1 C c a a -> ShowS
gshowsPrec' Type
_ Int
n c :: M1 C c a a
c@(M1 a a
x) =
    case Fixity
fixity of
      Fixity
Prefix    -> Bool -> ShowS -> ShowS
showParen (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
appPrec Bool -> Bool -> Bool
&& Bool -> Bool
not (a a -> Bool
forall (f :: * -> *) a. GShow' f => f a -> Bool
isNullary a a
x))
                    ( [Char] -> ShowS
showString (M1 C c a a -> [Char]
forall k (c :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
       (f :: k1 -> *) (a :: k1).
Constructor c =>
t c f a -> [Char]
conName M1 C c a a
c)
                    ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. if (a a -> Bool
forall (f :: * -> *) a. GShow' f => f a -> Bool
isNullary a a
x) then ShowS
forall a. a -> a
id else Char -> ShowS
showChar Char
' '
                    ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> ShowS -> ShowS
showBraces Type
t (Type -> Int -> a a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
appPrec a a
x))
      Infix Associativity
_ Int
m -> Bool -> ShowS -> ShowS
showParen (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
m) (Type -> ShowS -> ShowS
showBraces Type
t (Type -> Int -> a a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
m a a
x))
      where fixity :: Fixity
fixity = M1 C c a a -> Fixity
forall k (c :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
       (f :: k1 -> *) (a :: k1).
Constructor c =>
t c f a -> Fixity
conFixity M1 C c a a
c
            t :: Type
t = if (M1 C c a a -> Bool
forall k (c :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
       (f :: k1 -> *) (a :: k1).
Constructor c =>
t c f a -> Bool
conIsRecord M1 C c a a
c) then Type
Rec else
                  case (M1 C c a a -> Bool
forall (f :: * -> *) p. C1 c f p -> Bool
conIsTuple M1 C c a a
c) of
                    Bool
True -> Type
Tup
                    Bool
False -> case Fixity
fixity of
                                Fixity
Prefix    -> Type
Pref
                                Infix Associativity
_ Int
_ -> [Char] -> Type
Inf (ShowS
forall a. Show a => a -> [Char]
show (M1 C c a a -> [Char]
forall k (c :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
       (f :: k1 -> *) (a :: k1).
Constructor c =>
t c f a -> [Char]
conName M1 C c a a
c))
            showBraces :: Type -> ShowS -> ShowS
            showBraces :: Type -> ShowS -> ShowS
showBraces Type
Rec     ShowS
p = Char -> ShowS
showChar Char
'{' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
p ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'}'
            showBraces Type
Tup     ShowS
p = Char -> ShowS
showChar Char
'(' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
p ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
')'
            showBraces Type
Pref    ShowS
p = ShowS
p
            showBraces (Inf [Char]
_) ShowS
p = ShowS
p

            conIsTuple :: C1 c f p -> Bool
            conIsTuple :: C1 c f p -> Bool
conIsTuple C1 c f p
y = [Char] -> Bool
tupleName (C1 c f p -> [Char]
forall k (c :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
       (f :: k1 -> *) (a :: k1).
Constructor c =>
t c f a -> [Char]
conName C1 c f p
y) where
              tupleName :: [Char] -> Bool
tupleName (Char
'(':Char
',':[Char]
_) = Bool
True
              tupleName [Char]
_           = Bool
False

instance (Selector s, GShow' a) => GShow' (M1 S s a) where
  gshowsPrec' :: Type -> Int -> M1 S s a a -> ShowS
gshowsPrec' Type
t Int
n s :: M1 S s a a
s@(M1 a a
x) | M1 S s a a -> [Char]
forall k (s :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
       (f :: k1 -> *) (a :: k1).
Selector s =>
t s f a -> [Char]
selName M1 S s a a
s [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"" = --showParen (n > appPrec)
                                                 (Type -> Int -> a a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n a a
x)
                           | Bool
otherwise       =   [Char] -> ShowS
showString (M1 S s a a -> [Char]
forall k (s :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
       (f :: k1 -> *) (a :: k1).
Selector s =>
t s f a -> [Char]
selName M1 S s a a
s)
                                               ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
showString [Char]
" = "
                                               ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> Int -> a a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
0 a a
x
  isNullary :: M1 S s a a -> Bool
isNullary (M1 a a
x) = a a -> Bool
forall (f :: * -> *) a. GShow' f => f a -> Bool
isNullary a a
x

instance (GShow' a) => GShow' (M1 D d a) where
  gshowsPrec' :: Type -> Int -> M1 D d a a -> ShowS
gshowsPrec' Type
t Int
n (M1 a a
x) = Type -> Int -> a a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n a a
x

instance (GShow' a, GShow' b) => GShow' (a :+: b) where
  gshowsPrec' :: Type -> Int -> (:+:) a b a -> ShowS
gshowsPrec' Type
t Int
n (L1 a a
x) = Type -> Int -> a a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n a a
x
  gshowsPrec' Type
t Int
n (R1 b a
x) = Type -> Int -> b a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n b a
x

instance (GShow' a, GShow' b) => GShow' (a :*: b) where
  gshowsPrec' :: Type -> Int -> (:*:) a b a -> ShowS
gshowsPrec' t :: Type
t@Type
Rec     Int
n (a a
a :*: b a
b) =
    Type -> Int -> a a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n     a a
a ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
showString [Char]
", " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> Int -> b a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n     b a
b
  gshowsPrec' t :: Type
t@(Inf [Char]
s) Int
n (a a
a :*: b a
b) =
    Type -> Int -> a a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n     a a
a ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
showString [Char]
s    ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> Int -> b a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n     b a
b
  gshowsPrec' t :: Type
t@Type
Tup     Int
n (a a
a :*: b a
b) =
    Type -> Int -> a a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n     a a
a 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
. Type -> Int -> b a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n     b a
b
  gshowsPrec' t :: Type
t@Type
Pref    Int
n (a a
a :*: b a
b) =
    Type -> Int -> a a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) a a
a 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
. Type -> Int -> b a -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) b a
b

  -- If we have a product then it is not a nullary constructor
  isNullary :: (:*:) a b a -> Bool
isNullary (:*:) a b a
_ = Bool
False

-- Unboxed types
instance GShow' UChar where
  gshowsPrec' :: Type -> Int -> UChar a -> ShowS
gshowsPrec' Type
_ Int
_ (UChar c)   = Int -> Char -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
0 (Char# -> Char
C# Char#
c) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'#'
instance GShow' UDouble where
  gshowsPrec' :: Type -> Int -> UDouble a -> ShowS
gshowsPrec' Type
_ Int
_ (UDouble d) = Int -> Double -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
0 (Double# -> Double
D# Double#
d) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
showString [Char]
"##"
instance GShow' UFloat where
  gshowsPrec' :: Type -> Int -> UFloat a -> ShowS
gshowsPrec' Type
_ Int
_ (UFloat f)  = Int -> Float -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
0 (Float# -> Float
F# Float#
f) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'#'
instance GShow' UInt where
  gshowsPrec' :: Type -> Int -> UInt a -> ShowS
gshowsPrec' Type
_ Int
_ (UInt i)    = Int -> Int -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
0 (Int# -> Int
I# Int#
i) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'#'
instance GShow' UWord where
  gshowsPrec' :: Type -> Int -> UWord a -> ShowS
gshowsPrec' Type
_ Int
_ (UWord w)   = Int -> Word -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
0 (Word# -> Word
W# Word#
w) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
showString [Char]
"##"


class GShow a where
  gshowsPrec :: Int -> a -> ShowS
#if __GLASGOW_HASKELL__ >= 701
  default gshowsPrec :: (Generic a, GShow' (Rep a))
                     => Int -> a -> ShowS
  gshowsPrec = Int -> a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

  gshows :: a -> ShowS
  gshows = Int -> a -> ShowS
forall a. GShow a => Int -> a -> ShowS
gshowsPrec Int
0

  gshow :: a -> String
  gshow a
x = a -> ShowS
forall a. GShow a => a -> ShowS
gshows a
x [Char]
""

  gshowList :: [a] -> ShowS
  gshowList [a]
l =   Char -> ShowS
showChar Char
'['
                ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ShowS -> ShowS -> ShowS) -> ShowS -> [ShowS] -> ShowS
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) ShowS
forall a. a -> a
id
                   (ShowS -> [ShowS] -> [ShowS]
forall a. a -> [a] -> [a]
intersperse (Char -> ShowS
showChar Char
',') ((a -> ShowS) -> [a] -> [ShowS]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> a -> ShowS
forall a. GShow a => Int -> a -> ShowS
gshowsPrec Int
0) [a]
l))
                ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
']'

gshowsPrecdefault :: (Generic a, GShow' (Rep a))
                  => Int -> a -> ShowS
gshowsPrecdefault :: Int -> a -> ShowS
gshowsPrecdefault Int
n = Type -> Int -> Rep a Any -> ShowS
forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
Pref Int
n (Rep a Any -> ShowS) -> (a -> Rep a Any) -> a -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Rep a Any
forall a x. Generic a => a -> Rep a x
from


-- Base types instances
-- Base types instances
instance GShow () where
  gshowsPrec :: Int -> () -> ShowS
gshowsPrec = Int -> () -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance (GShow a, GShow b) => GShow (a, b) where
  gshowsPrec :: Int -> (a, b) -> ShowS
gshowsPrec = Int -> (a, b) -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance (GShow a, GShow b, GShow c) => GShow (a, b, c) where
  gshowsPrec :: Int -> (a, b, c) -> ShowS
gshowsPrec = Int -> (a, b, c) -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance (GShow a, GShow b, GShow c, GShow d) => GShow (a, b, c, d) where
  gshowsPrec :: Int -> (a, b, c, d) -> ShowS
gshowsPrec = Int -> (a, b, c, d) -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance (GShow a, GShow b, GShow c, GShow d, GShow e) => GShow (a, b, c, d, e) where
  gshowsPrec :: Int -> (a, b, c, d, e) -> ShowS
gshowsPrec = Int -> (a, b, c, d, e) -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance (GShow a, GShow b, GShow c, GShow d, GShow e, GShow f)
    => GShow (a, b, c, d, e, f) where
  gshowsPrec :: Int -> (a, b, c, d, e, f) -> ShowS
gshowsPrec = Int -> (a, b, c, d, e, f) -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance (GShow a, GShow b, GShow c, GShow d, GShow e, GShow f, GShow g)
    => GShow (a, b, c, d, e, f, g) where
  gshowsPrec :: Int -> (a, b, c, d, e, f, g) -> ShowS
gshowsPrec = Int -> (a, b, c, d, e, f, g) -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow a => GShow [a] where
  gshowsPrec :: Int -> [a] -> ShowS
gshowsPrec Int
_ = [a] -> ShowS
forall a. GShow a => [a] -> ShowS
gshowList

instance (GShow (f p), GShow (g p)) => GShow ((f :+: g) p) where
  gshowsPrec :: Int -> (:+:) f g p -> ShowS
gshowsPrec = Int -> (:+:) f g p -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance (GShow (f p), GShow (g p)) => GShow ((f :*: g) p) where
  gshowsPrec :: Int -> (:*:) f g p -> ShowS
gshowsPrec = Int -> (:*:) f g p -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow (f (g p)) => GShow ((f :.: g) p) where
  gshowsPrec :: Int -> (:.:) f g p -> ShowS
gshowsPrec = Int -> (:.:) f g p -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow All where
  gshowsPrec :: Int -> All -> ShowS
gshowsPrec = Int -> All -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

#if MIN_VERSION_base(4,8,0)
instance GShow (f a) => GShow (Alt f a) where
  gshowsPrec :: Int -> Alt f a -> ShowS
gshowsPrec = Int -> Alt f a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

instance GShow Any where
  gshowsPrec :: Int -> Any -> ShowS
gshowsPrec = Int -> Any -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

#if MIN_VERSION_base(4,9,0)
instance (GShow a, GShow b) => GShow (Arg a b) where
  gshowsPrec :: Int -> Arg a b -> ShowS
gshowsPrec = Int -> Arg a b -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

#if !(MIN_VERSION_base(4,9,0))
instance GShow Arity where
  gshowsPrec = gshowsPrecdefault
#endif

instance GShow Associativity where
  gshowsPrec :: Int -> Associativity -> ShowS
gshowsPrec = Int -> Associativity -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow Bool where
  gshowsPrec :: Int -> Bool -> ShowS
gshowsPrec = Int -> Bool -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow BufferMode where
  gshowsPrec :: Int -> BufferMode -> ShowS
gshowsPrec = Int -> BufferMode -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

#if defined(HTYPE_CC_T)
instance GShow CCc where
  gshowsPrec = showsPrec
#endif

instance GShow CChar where
  gshowsPrec :: Int -> CChar -> ShowS
gshowsPrec = Int -> CChar -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CClock where
  gshowsPrec :: Int -> CClock -> ShowS
gshowsPrec = Int -> CClock -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

#if defined(HTYPE_DEV_T)
instance GShow CDev where
  gshowsPrec = showsPrec
#endif

instance GShow CDouble where
  gshowsPrec :: Int -> CDouble -> ShowS
gshowsPrec = Int -> CDouble -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CFloat where
  gshowsPrec :: Int -> CFloat -> ShowS
gshowsPrec = Int -> CFloat -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

#if defined(HTYPE_GID_T)
instance GShow CGid where
  gshowsPrec = showsPrec
#endif

instance GShow Char where
  gshowsPrec :: Int -> Char -> ShowS
gshowsPrec = Int -> Char -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec
  gshowList :: [Char] -> ShowS
gshowList  = [Char] -> ShowS
forall a. Show a => [a] -> ShowS
showList

#if defined(HTYPE_INO_T)
instance GShow CIno where
  gshowsPrec = showsPrec
#endif

instance GShow CInt where
  gshowsPrec :: Int -> CInt -> ShowS
gshowsPrec = Int -> CInt -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CIntMax where
  gshowsPrec :: Int -> CIntMax -> ShowS
gshowsPrec = Int -> CIntMax -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CIntPtr where
  gshowsPrec :: Int -> CIntPtr -> ShowS
gshowsPrec = Int -> CIntPtr -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CLLong where
  gshowsPrec :: Int -> CLLong -> ShowS
gshowsPrec = Int -> CLLong -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CLong where
  gshowsPrec :: Int -> CLong -> ShowS
gshowsPrec = Int -> CLong -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

#if defined(HTYPE_MODE_T)
instance GShow CMode where
  gshowsPrec = showsPrec
#endif

#if defined(HTYPE_NLINK_T)
instance GShow CNlink where
  gshowsPrec = showsPrec
#endif

#if defined(HTYPE_OFF_T)
instance GShow COff where
  gshowsPrec = showsPrec
#endif

#if MIN_VERSION_base(4,4,0)
instance GShow a => GShow (Complex a) where
  gshowsPrec :: Int -> Complex a -> ShowS
gshowsPrec = Int -> Complex a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

instance GShow a => GShow (Const a b) where
  gshowsPrec :: Int -> Const a b -> ShowS
gshowsPrec = Int -> Const a b -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

#if defined(HTYPE_PID_T)
instance GShow CPid where
  gshowsPrec = showsPrec
#endif

instance GShow CPtrdiff where
  gshowsPrec :: Int -> CPtrdiff -> ShowS
gshowsPrec = Int -> CPtrdiff -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

#if defined(HTYPE_RLIM_T)
instance GShow CRLim where
  gshowsPrec = showsPrec
#endif

instance GShow CSChar where
  gshowsPrec :: Int -> CSChar -> ShowS
gshowsPrec = Int -> CSChar -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

#if defined(HTYPE_SPEED_T)
instance GShow CSpeed where
  gshowsPrec = showsPrec
#endif

#if MIN_VERSION_base(4,4,0)
instance GShow CSUSeconds where
  gshowsPrec :: Int -> CSUSeconds -> ShowS
gshowsPrec = Int -> CSUSeconds -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec
#endif

instance GShow CShort where
  gshowsPrec :: Int -> CShort -> ShowS
gshowsPrec = Int -> CShort -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CSigAtomic where
  gshowsPrec :: Int -> CSigAtomic -> ShowS
gshowsPrec = Int -> CSigAtomic -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CSize where
  gshowsPrec :: Int -> CSize -> ShowS
gshowsPrec = Int -> CSize -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

#if defined(HTYPE_SSIZE_T)
instance GShow CSsize where
  gshowsPrec = showsPrec
#endif

#if defined(HTYPE_TCFLAG_T)
instance GShow CTcflag where
  gshowsPrec = showsPrec
#endif

instance GShow CTime where
  gshowsPrec :: Int -> CTime -> ShowS
gshowsPrec = Int -> CTime -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CUChar where
  gshowsPrec :: Int -> CUChar -> ShowS
gshowsPrec = Int -> CUChar -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

#if defined(HTYPE_UID_T)
instance GShow CUid where
  gshowsPrec = showsPrec
#endif

instance GShow CUInt where
  gshowsPrec :: Int -> CUInt -> ShowS
gshowsPrec = Int -> CUInt -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CUIntMax where
  gshowsPrec :: Int -> CUIntMax -> ShowS
gshowsPrec = Int -> CUIntMax -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CUIntPtr where
  gshowsPrec :: Int -> CUIntPtr -> ShowS
gshowsPrec = Int -> CUIntPtr -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CULLong where
  gshowsPrec :: Int -> CULLong -> ShowS
gshowsPrec = Int -> CULLong -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CULong where
  gshowsPrec :: Int -> CULong -> ShowS
gshowsPrec = Int -> CULong -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

#if MIN_VERSION_base(4,4,0)
instance GShow CUSeconds where
  gshowsPrec :: Int -> CUSeconds -> ShowS
gshowsPrec = Int -> CUSeconds -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec
#endif

instance GShow CUShort where
  gshowsPrec :: Int -> CUShort -> ShowS
gshowsPrec = Int -> CUShort -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CWchar where
  gshowsPrec :: Int -> CWchar -> ShowS
gshowsPrec = Int -> CWchar -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow Double where
  gshowsPrec :: Int -> Double -> ShowS
gshowsPrec = Int -> Double -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow a => GShow (Down a) where
  gshowsPrec :: Int -> Down a -> ShowS
gshowsPrec = Int -> Down a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow a => GShow (Dual a) where
  gshowsPrec :: Int -> Dual a -> ShowS
gshowsPrec = Int -> Dual a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance (GShow a, GShow b) => GShow (Either a b) where
  gshowsPrec :: Int -> Either a b -> ShowS
gshowsPrec = Int -> Either a b -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow ExitCode where
  gshowsPrec :: Int -> ExitCode -> ShowS
gshowsPrec = Int -> ExitCode -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow Fd where
  gshowsPrec :: Int -> Fd -> ShowS
gshowsPrec = Int -> Fd -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow a => GShow (Monoid.First a) where
  gshowsPrec :: Int -> First a -> ShowS
gshowsPrec = Int -> First a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

#if MIN_VERSION_base(4,9,0)
instance GShow a => GShow (Semigroup.First a) where
  gshowsPrec :: Int -> First a -> ShowS
gshowsPrec = Int -> First a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

instance GShow Fixity where
  gshowsPrec :: Int -> Fixity -> ShowS
gshowsPrec = Int -> Fixity -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow Float where
  gshowsPrec :: Int -> Float -> ShowS
gshowsPrec = Int -> Float -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow (ForeignPtr a) where
  gshowsPrec :: Int -> ForeignPtr a -> ShowS
gshowsPrec = Int -> ForeignPtr a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow (FunPtr a) where
  gshowsPrec :: Int -> FunPtr a -> ShowS
gshowsPrec = Int -> FunPtr a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow GeneralCategory where
  gshowsPrec :: Int -> GeneralCategory -> ShowS
gshowsPrec = Int -> GeneralCategory -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow Handle where
  gshowsPrec :: Int -> Handle -> ShowS
gshowsPrec = Int -> Handle -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow HandlePosn where
  gshowsPrec :: Int -> HandlePosn -> ShowS
gshowsPrec = Int -> HandlePosn -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

#if MIN_VERSION_base(4,8,0)
instance GShow a => GShow (Identity a) where
  gshowsPrec :: Int -> Identity a -> ShowS
gshowsPrec = Int -> Identity a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

instance GShow Int where
  gshowsPrec :: Int -> Int -> ShowS
gshowsPrec = Int -> Int -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow Int8 where
  gshowsPrec :: Int -> Int8 -> ShowS
gshowsPrec = Int -> Int8 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow Int16 where
  gshowsPrec :: Int -> Int16 -> ShowS
gshowsPrec = Int -> Int16 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow Int32 where
  gshowsPrec :: Int -> Int32 -> ShowS
gshowsPrec = Int -> Int32 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow Int64 where
  gshowsPrec :: Int -> Int64 -> ShowS
gshowsPrec = Int -> Int64 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow Integer where
  gshowsPrec :: Int -> Integer -> ShowS
gshowsPrec = Int -> Integer -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow IntPtr where
  gshowsPrec :: Int -> IntPtr -> ShowS
gshowsPrec = Int -> IntPtr -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow IOError where
  gshowsPrec :: Int -> IOError -> ShowS
gshowsPrec = Int -> IOError -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow IOErrorType where
  gshowsPrec :: Int -> IOErrorType -> ShowS
gshowsPrec = Int -> IOErrorType -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow IOMode where
  gshowsPrec :: Int -> IOMode -> ShowS
gshowsPrec = Int -> IOMode -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow c => GShow (K1 i c p) where
  gshowsPrec :: Int -> K1 i c p -> ShowS
gshowsPrec = Int -> K1 i c p -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow a => GShow (Monoid.Last a) where
  gshowsPrec :: Int -> Last a -> ShowS
gshowsPrec = Int -> Last a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

#if MIN_VERSION_base(4,9,0)
instance GShow a => GShow (Semigroup.Last a) where
  gshowsPrec :: Int -> Last a -> ShowS
gshowsPrec = Int -> Last a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

instance GShow (f p) => GShow (M1 i c f p) where
  gshowsPrec :: Int -> M1 i c f p -> ShowS
gshowsPrec = Int -> M1 i c f p -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

#if MIN_VERSION_base(4,9,0)
instance GShow a => GShow (Max a) where
  gshowsPrec :: Int -> Max a -> ShowS
gshowsPrec = Int -> Max a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

instance GShow a => GShow (Maybe a) where
  gshowsPrec :: Int -> Maybe a -> ShowS
gshowsPrec = Int -> Maybe a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

#if MIN_VERSION_base(4,9,0)
instance GShow a => GShow (Min a) where
  gshowsPrec :: Int -> Min a -> ShowS
gshowsPrec = Int -> Min a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

#if MIN_VERSION_base(4,8,0)
instance GShow Natural where
  gshowsPrec :: Int -> Natural -> ShowS
gshowsPrec = Int -> Natural -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec
#endif

#if MIN_VERSION_base(4,9,0)
instance GShow a => GShow (NonEmpty a) where
  gshowsPrec :: Int -> NonEmpty a -> ShowS
gshowsPrec = Int -> NonEmpty a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

instance GShow Ordering where
  gshowsPrec :: Int -> Ordering -> ShowS
gshowsPrec = Int -> Ordering -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow p => GShow (Par1 p) where
  gshowsPrec :: Int -> Par1 p -> ShowS
gshowsPrec = Int -> Par1 p -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow a => GShow (Product a) where
  gshowsPrec :: Int -> Product a -> ShowS
gshowsPrec = Int -> Product a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

#if MIN_VERSION_base(4,7,0)
instance GShow (Proxy s) where
  gshowsPrec :: Int -> Proxy s -> ShowS
gshowsPrec = Int -> Proxy s -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

instance GShow (Ptr a) where
  gshowsPrec :: Int -> Ptr a -> ShowS
gshowsPrec = Int -> Ptr a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow (f p) => GShow (Rec1 f p) where
  gshowsPrec :: Int -> Rec1 f p -> ShowS
gshowsPrec = Int -> Rec1 f p -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow SeekMode where
  gshowsPrec :: Int -> SeekMode -> ShowS
gshowsPrec = Int -> SeekMode -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow a => GShow (Sum a) where
  gshowsPrec :: Int -> Sum a -> ShowS
gshowsPrec = Int -> Sum a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow (U1 p) where
  gshowsPrec :: Int -> U1 p -> ShowS
gshowsPrec = Int -> U1 p -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow (UChar p) where
  gshowsPrec :: Int -> UChar p -> ShowS
gshowsPrec = Int -> UChar p -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow (UDouble p) where
  gshowsPrec :: Int -> UDouble p -> ShowS
gshowsPrec = Int -> UDouble p -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow (UFloat p) where
  gshowsPrec :: Int -> UFloat p -> ShowS
gshowsPrec = Int -> UFloat p -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow (UInt p) where
  gshowsPrec :: Int -> UInt p -> ShowS
gshowsPrec = Int -> UInt p -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow (UWord p) where
  gshowsPrec :: Int -> UWord p -> ShowS
gshowsPrec = Int -> UWord p -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow Version where
  gshowsPrec :: Int -> Version -> ShowS
gshowsPrec = Int -> Version -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

#if MIN_VERSION_base(4,8,0)
instance GShow Void where
  gshowsPrec :: Int -> Void -> ShowS
gshowsPrec = Int -> Void -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec
#endif

instance GShow Word where
  gshowsPrec :: Int -> Word -> ShowS
gshowsPrec = Int -> Word -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow Word8 where
  gshowsPrec :: Int -> Word8 -> ShowS
gshowsPrec = Int -> Word8 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow Word16 where
  gshowsPrec :: Int -> Word16 -> ShowS
gshowsPrec = Int -> Word16 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow Word32 where
  gshowsPrec :: Int -> Word32 -> ShowS
gshowsPrec = Int -> Word32 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow Word64 where
  gshowsPrec :: Int -> Word64 -> ShowS
gshowsPrec = Int -> Word64 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow WordPtr where
  gshowsPrec :: Int -> WordPtr -> ShowS
gshowsPrec = Int -> WordPtr -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

#if MIN_VERSION_base(4,9,0)
instance GShow m => GShow (WrappedMonoid m) where
  gshowsPrec :: Int -> WrappedMonoid m -> ShowS
gshowsPrec = Int -> WrappedMonoid m -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

instance GShow a => GShow (ZipList a) where
  gshowsPrec :: Int -> ZipList a -> ShowS
gshowsPrec = Int -> ZipList a -> ShowS
forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

#if MIN_VERSION_base(4,10,0)
instance GShow CBool where
  gshowsPrec :: Int -> CBool -> ShowS
gshowsPrec = Int -> CBool -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec

# if defined(HTYPE_BLKSIZE_T)
instance GShow CBlkSize where
  gshowsPrec = showsPrec
# endif

# if defined(HTYPE_BLKCNT_T)
instance GShow CBlkCnt where
  gshowsPrec = showsPrec
# endif

# if defined(HTYPE_CLOCKID_T)
instance GShow CClockId where
  gshowsPrec = showsPrec
# endif

# if defined(HTYPE_FSBLKCNT_T)
instance GShow CFsBlkCnt where
  gshowsPrec = showsPrec
# endif

# if defined(HTYPE_FSFILCNT_T)
instance GShow CFsFilCnt where
  gshowsPrec = showsPrec
# endif

# if defined(HTYPE_ID_T)
instance GShow CId where
  gshowsPrec = showsPrec
# endif

# if defined(HTYPE_KEY_T)
instance GShow CKey where
  gshowsPrec = showsPrec
# endif

# if defined(HTYPE_TIMER_T)
instance GShow CTimer where
  gshowsPrec = showsPrec
# endif
#endif