{-# 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 :: forall a. a -> [a] -> [a]
intersperse a
_ []    = []
intersperse a
_ [a
h]   = [a
h]
intersperse a
x (a
h:[a]
t) = a
h forall a. a -> [a] -> [a]
: a
x forall 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 = forall a. HasCallStack => [Char] -> a
error [Char]
"generic show (isNullary): unnecessary case"

instance GShow' V1 where
  gshowsPrec' :: forall a. 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' :: forall a. Type -> Int -> U1 a -> ShowS
gshowsPrec' Type
_ Int
_ U1 a
U1 = forall a. a -> a
id
  isNullary :: forall a. U1 a -> Bool
isNullary U1 a
_ = Bool
True

instance (GShow c) => GShow' (K1 i c) where
  gshowsPrec' :: forall a. Type -> Int -> K1 i c a -> ShowS
gshowsPrec' Type
_ Int
n (K1 c
a) = forall a. GShow a => Int -> a -> ShowS
gshowsPrec Int
n c
a
  isNullary :: forall a. 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' :: forall a. 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 forall a. Ord a => a -> a -> Bool
> Int
appPrec Bool -> Bool -> Bool
&& Bool -> Bool
not (forall (f :: * -> *) a. GShow' f => f a -> Bool
isNullary a a
x))
                    ( [Char] -> ShowS
showString (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)
                    forall b c a. (b -> c) -> (a -> b) -> a -> c
. if (forall (f :: * -> *) a. GShow' f => f a -> Bool
isNullary a a
x) then forall a. a -> a
id else Char -> ShowS
showChar Char
' '
                    forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> ShowS -> ShowS
showBraces Type
t (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 forall a. Ord a => a -> a -> Bool
> Int
m) (Type -> ShowS -> ShowS
showBraces Type
t (forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
m a a
x))
      where fixity :: Fixity
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 (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 (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 (forall a. Show a => a -> [Char]
show (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
'{' forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'}'
            showBraces Type
Tup     ShowS
p = Char -> ShowS
showChar Char
'(' forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
p 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 :: forall (f :: * -> *) p. C1 c f p -> Bool
conIsTuple C1 c f p
y = [Char] -> Bool
tupleName (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' :: forall a. Type -> Int -> M1 S s a a -> ShowS
gshowsPrec' Type
t Int
n s :: M1 S s a a
s@(M1 a a
x) | 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 forall a. Eq a => a -> a -> Bool
== [Char]
"" = --showParen (n > appPrec)
                                                 (forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n a a
x)
                           | Bool
otherwise       =   [Char] -> ShowS
showString (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)
                                               forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
showString [Char]
" = "
                                               forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
0 a a
x
  isNullary :: forall a. M1 S s a a -> Bool
isNullary (M1 a a
x) = forall (f :: * -> *) a. GShow' f => f a -> Bool
isNullary a a
x

instance (GShow' a) => GShow' (M1 D d a) where
  gshowsPrec' :: forall a. Type -> Int -> M1 D d a a -> ShowS
gshowsPrec' Type
t Int
n (M1 a a
x) = 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' :: forall a. Type -> Int -> (:+:) a b a -> ShowS
gshowsPrec' Type
t Int
n (L1 a a
x) = 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) = 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' :: forall a. Type -> Int -> (:*:) a b a -> ShowS
gshowsPrec' t :: Type
t@Type
Rec     Int
n (a a
a :*: b a
b) =
    forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n     a a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
showString [Char]
", " forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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) =
    forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n     a a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
showString [Char]
s    forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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) =
    forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t Int
n     a a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
','    forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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) =
    forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t (Int
nforall a. Num a => a -> a -> a
+Int
1) a a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' '    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. GShow' f => Type -> Int -> f a -> ShowS
gshowsPrec' Type
t (Int
nforall a. Num a => a -> a -> a
+Int
1) b a
b

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

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

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

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

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

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


-- Base types instances
-- Base types instances
instance GShow () where
  gshowsPrec :: Int -> () -> ShowS
gshowsPrec = 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 = 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 = 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 = 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 = 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 = 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 = forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow a => GShow [a] where
  gshowsPrec :: Int -> [a] -> ShowS
gshowsPrec Int
_ = 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 = 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 = 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 = forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

instance GShow All where
  gshowsPrec :: Int -> All -> ShowS
gshowsPrec = 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 = forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

instance GShow Any where
  gshowsPrec :: Int -> Any -> ShowS
gshowsPrec = 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 = 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 = forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

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

instance GShow BufferMode where
  gshowsPrec :: Int -> BufferMode -> ShowS
gshowsPrec = 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 = forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CClock where
  gshowsPrec :: Int -> CClock -> ShowS
gshowsPrec = 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 = forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CFloat where
  gshowsPrec :: Int -> CFloat -> ShowS
gshowsPrec = 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 = forall a. Show a => Int -> a -> ShowS
showsPrec
  gshowList :: [Char] -> ShowS
gshowList  = 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 = forall a. Show a => Int -> a -> ShowS
showsPrec

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

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

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

instance GShow CLong where
  gshowsPrec :: Int -> CLong -> ShowS
gshowsPrec = 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 = 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 = 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 = 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 = 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 = forall a. Show a => Int -> a -> ShowS
showsPrec
#endif

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

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

instance GShow CSize where
  gshowsPrec :: Int -> CSize -> ShowS
gshowsPrec = 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 = forall a. Show a => Int -> a -> ShowS
showsPrec

instance GShow CUChar where
  gshowsPrec :: Int -> CUChar -> ShowS
gshowsPrec = 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 = forall a. Show a => Int -> a -> ShowS
showsPrec

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

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

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

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

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

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

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

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

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

instance GShow a => GShow (Dual a) where
  gshowsPrec :: Int -> Dual a -> ShowS
gshowsPrec = 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 = forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault

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

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

instance GShow a => GShow (Monoid.First a) where
  gshowsPrec :: Int -> First a -> ShowS
gshowsPrec = 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 = forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

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

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

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

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

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

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

instance GShow HandlePosn where
  gshowsPrec :: Int -> HandlePosn -> ShowS
gshowsPrec = 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 = forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

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

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

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

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

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

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

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

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

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

instance GShow IOMode where
  gshowsPrec :: Int -> IOMode -> ShowS
gshowsPrec = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

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

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

instance GShow a => GShow (Product a) where
  gshowsPrec :: Int -> Product a -> ShowS
gshowsPrec = 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 = forall a. (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
gshowsPrecdefault
#endif

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

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

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

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

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

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

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

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

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

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

instance GShow Version where
  gshowsPrec :: Int -> Version -> ShowS
gshowsPrec = 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 = forall a. Show a => Int -> a -> ShowS
showsPrec
#endif

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

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

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

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

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

instance GShow WordPtr where
  gshowsPrec :: Int -> WordPtr -> ShowS
gshowsPrec = 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 = 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 = 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 = 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