----------------------------------------------------------------------------
-- |
-- Module      :  Prettyprinter.Generics
-- Copyright   :  (c) Sergey Vinokurov 2018
-- License     :  Apache-2.0 (see LICENSE)
-- Maintainer  :  serg.foo@gmail.com
----------------------------------------------------------------------------

{-# LANGUAGE CPP                  #-}
{-# LANGUAGE DataKinds            #-}
{-# LANGUAGE LambdaCase           #-}
{-# LANGUAGE OverloadedStrings    #-}
{-# LANGUAGE TypeApplications     #-}
{-# LANGUAGE TypeFamilies         #-}
{-# LANGUAGE UndecidableInstances #-}

module Prettyprinter.Generics
  ( ppGeneric
  , PPGeneric(..)
  , PPGenericOverride(..)
  , Pretty(..)
  , Generic
  ) where

import Data.Bimap (Bimap)
import Data.ByteString.Char8 qualified as C8
import Data.ByteString.Lazy.Char8 qualified as CL8
import Data.ByteString.Short qualified as ShortBS
import Data.DList (DList)
import Data.DList qualified as DList
import Data.Foldable
import Data.Functor.Compose
import Data.HashMap.Strict (HashMap)
import Data.HashSet (HashSet)
import Data.Int
import Data.IntMap (IntMap)
import Data.IntSet qualified as IntSet
import Data.Kind
import Data.List.NonEmpty (NonEmpty)
import Data.Map (Map)
import Data.Proxy
import Data.Semigroup qualified as Semigroup
import Data.Set (Set)
import Data.Text (Text)
import Data.Text qualified as T
import Data.Text.Lazy qualified as TL
import Data.Vector (Vector)
import Data.Void
import Data.Word
import GHC.ForeignPtr (ForeignPtr(..))
import GHC.Generics
import GHC.Real (Ratio(..))
import GHC.Stack (CallStack)
import GHC.TypeLits

import Prettyprinter
import Prettyprinter.Combinators
import Prettyprinter.MetaDoc

import Language.Haskell.TH qualified as TH
import Language.Haskell.TH.Syntax qualified as TH

-- $setup
-- >>> :set -XDeriveGeneric
-- >>> :set -XDerivingVia
-- >>> :set -XImportQualifiedPost
-- >>> import Data.List.NonEmpty (NonEmpty(..))
-- >>> import Data.List.NonEmpty qualified as NonEmpty
-- >>> import Data.IntMap (IntMap)
-- >>> import Data.IntMap qualified as IntMap
-- >>> import Data.IntSet (IntSet)
-- >>> import Data.IntSet qualified as IntSet
-- >>> import Data.Map.Strict (Map)
-- >>> import Data.Map.Strict qualified as Map
-- >>> import Data.Set (Set)
-- >>> import Data.Set qualified as Set
-- >>> import Data.Vector (Vector)
-- >>> import Data.Vector qualified as Vector
-- >>> import GHC.Generics (Generic)
--
-- >>> :{
-- data Test = Test
--   { testSet         :: Maybe (Set Int)
--   , testMap         :: Map String (Set Double)
--   , testIntSet      :: IntSet
--   , testIntMap      :: IntMap String
--   , testInt         :: Int
--   , testComplexMap  :: Map (Maybe (Set Int)) (IntMap (Set String))
--   , testComplexMap2 :: Map (Maybe (Set Int)) (Map (NonEmpty Int) (Vector String))
--   } deriving (Generic)
-- :}

-- | Helper to use 'GHC.Generics.Generic'-based prettyprinting with DerivingVia.
--
-- >>> :{
-- data TestWithDeriving a b = TestWithDeriving
--   { testSet         :: Maybe (Set a)
--   , testB           :: b
--   , testIntMap      :: IntMap String
--   , testComplexMap  :: Map (Maybe (Set Int)) (IntMap (Set String))
--   }
--   deriving (Generic)
--   deriving Pretty via PPGeneric (TestWithDeriving a b)
-- :}
--
newtype PPGeneric a = PPGeneric { forall a. PPGeneric a -> a
unPPGeneric :: a }

instance (Generic a, GPretty (Rep a)) => Pretty (PPGeneric a) where
  pretty :: forall ann. PPGeneric a -> Doc ann
pretty = forall a ann. (Generic a, GPretty (Rep a)) => a -> Doc ann
ppGeneric forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PPGeneric a -> a
unPPGeneric

-- | Prettyprint using 'GHC.Generics.Generic' instance.
--
-- >>> :{
-- test = Test
--   { testSet         = Just $ Set.fromList [1..3]
--   , testMap         =
--       Map.fromList [("foo", Set.fromList [1.5]), ("foo", Set.fromList [2.5, 3, 4])]
--   , testIntSet      = IntSet.fromList [1, 2, 4, 5, 7]
--   , testIntMap      = IntMap.fromList $ zip [1..] ["3", "2foo", "11"]
--   , testInt         = 42
--   , testComplexMap  = Map.fromList
--       [ ( Nothing
--         , IntMap.fromList $ zip [0..] $ map Set.fromList
--             [ ["foo", "bar"]
--             , ["baz"]
--             , ["quux", "frob"]
--             ]
--         )
--       , ( Just (Set.fromList [1])
--         , IntMap.fromList $ zip [0..] $ map Set.fromList
--             [ ["quux"]
--             , ["fizz", "buzz"]
--             ]
--         )
--       , ( Just (Set.fromList [3, 4])
--         , IntMap.fromList $ zip [0..] $ map Set.fromList
--             [ ["quux", "5"]
--             , []
--             , ["fizz", "buzz"]
--             ]
--         )
--       ]
--   , testComplexMap2 =
--       Map.singleton
--         (Just (Set.fromList [1..5]))
--         (Map.fromList
--            [ (NonEmpty.fromList [1, 2],  Vector.fromList ["foo", "bar", "baz"])
--            , (NonEmpty.fromList [3],     Vector.fromList ["quux"])
--            , (NonEmpty.fromList [4..10], Vector.fromList ["must", "put", "something", "in", "here"])
--            ])
--   }
-- :}
--
-- >>> ppGeneric test
-- Test
--   { testSet         -> Just ({1, 2, 3})
--   , testMap         -> {foo -> {2.5, 3.0, 4.0}}
--   , testIntSet      -> {1, 2, 4, 5, 7}
--   , testIntMap      -> {1 -> 3, 2 -> 2foo, 3 -> 11}
--   , testInt         -> 42
--   , testComplexMap  ->
--       { Nothing -> {0 -> {bar, foo}, 1 -> {baz}, 2 -> {frob, quux}}
--       , Just ({1}) -> {0 -> {quux}, 1 -> {buzz, fizz}}
--       , Just ({3, 4}) -> {0 -> {5, quux}, 1 -> {}, 2 -> {buzz, fizz}}
--       }
--   , testComplexMap2 ->
--       { Just ({1, 2, 3, 4, 5}) ->
--           { [1, 2] -> [foo, bar, baz]
--           , [3] -> [quux]
--           , [4, 5, 6, 7, 8, 9, 10] -> [must, put, something, in, here]
--           } }
--   }
ppGeneric :: (Generic a, GPretty (Rep a)) => a -> Doc ann
ppGeneric :: forall a ann. (Generic a, GPretty (Rep a)) => a -> Doc ann
ppGeneric = forall ann. MetaDoc ann -> Doc ann
mdPayload forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from

class GPretty (a :: Type -> Type) where
  gpretty :: a ix -> MetaDoc ann

instance GPretty V1 where
  gpretty :: forall ix ann. V1 ix -> MetaDoc ann
gpretty V1 ix
_ = forall a. HasCallStack => [Char] -> a
error [Char]
"gpretty for V1"

instance GPretty U1 where
  gpretty :: forall ix ann. U1 ix -> MetaDoc ann
gpretty U1 ix
U1 = forall a. Monoid a => a
mempty

instance (GPretty f, GPretty g) => GPretty (f :+: g) where
  gpretty :: forall ix ann. (:+:) f g ix -> MetaDoc ann
gpretty = \case
    L1 f ix
x -> forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty f ix
x
    R1 g ix
y -> forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty g ix
y

-- 'PPGenericDeriving' to give it a chance to fire before standard 'Pretty'.
instance PPGenericOverride a => GPretty (K1 i a) where
  gpretty :: forall ix ann. K1 i a ix -> MetaDoc ann
gpretty = forall a ann. PPGenericOverride a => a -> MetaDoc ann
ppGenericOverride forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i c (p :: k). K1 i c p -> c
unK1


-- | A class to override 'Pretty' when calling 'ppGeneric' without introducing
-- orphans for standard types.
class PPGenericOverride a where
  ppGenericOverride :: a -> MetaDoc ann

ppGenericOverrideDoc :: PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc :: forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc = forall ann. MetaDoc ann -> Doc ann
mdPayload forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a ann. PPGenericOverride a => a -> MetaDoc ann
ppGenericOverride

newtype PPGenericOverrideToPretty a = PPGenericOverrideToPretty { forall a. PPGenericOverrideToPretty a -> a
unPPGenericOverrideToPretty :: a }

instance PPGenericOverride a => Pretty (PPGenericOverrideToPretty a) where
  pretty :: forall ann. PPGenericOverrideToPretty a -> Doc ann
pretty = forall ann. MetaDoc ann -> Doc ann
mdPayload forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a ann. PPGenericOverride a => a -> MetaDoc ann
ppGenericOverride forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. PPGenericOverrideToPretty a -> a
unPPGenericOverrideToPretty


-- | Fall back to standard 'Pretty' instance when no override is available.
instance Pretty a => PPGenericOverride a where
  ppGenericOverride :: forall ann. a -> MetaDoc ann
ppGenericOverride = forall ann. Doc ann -> MetaDoc ann
compositeMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a ann. Pretty a => a -> Doc ann
pretty


instance {-# OVERLAPS #-} PPGenericOverride Int where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Int -> MetaDoc ann
ppGenericOverride = forall ann. Int -> MetaDoc ann
metaDocInt

instance {-# OVERLAPS #-} PPGenericOverride Float where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Float -> MetaDoc ann
ppGenericOverride = forall ann. Float -> MetaDoc ann
metaDocFloat

instance {-# OVERLAPS #-} PPGenericOverride Double where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Double -> MetaDoc ann
ppGenericOverride = forall ann. Double -> MetaDoc ann
metaDocDouble

instance {-# OVERLAPS #-} PPGenericOverride Integer where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Integer -> MetaDoc ann
ppGenericOverride = forall ann. Integer -> MetaDoc ann
metaDocInteger

instance {-# OVERLAPS #-} PPGenericOverride Natural where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Natural -> MetaDoc ann
ppGenericOverride = forall ann. Natural -> MetaDoc ann
metaDocNatural

instance {-# OVERLAPS #-} PPGenericOverride Word where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Word -> MetaDoc ann
ppGenericOverride = forall ann. Word -> MetaDoc ann
metaDocWord

instance {-# OVERLAPS #-} PPGenericOverride Word8 where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Word8 -> MetaDoc ann
ppGenericOverride = forall ann. Word8 -> MetaDoc ann
metaDocWord8

instance {-# OVERLAPS #-} PPGenericOverride Word16 where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Word16 -> MetaDoc ann
ppGenericOverride = forall ann. Word16 -> MetaDoc ann
metaDocWord16

instance {-# OVERLAPS #-} PPGenericOverride Word32 where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Word32 -> MetaDoc ann
ppGenericOverride = forall ann. Word32 -> MetaDoc ann
metaDocWord32

instance {-# OVERLAPS #-} PPGenericOverride Word64 where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Word64 -> MetaDoc ann
ppGenericOverride = forall ann. Word64 -> MetaDoc ann
metaDocWord64

instance {-# OVERLAPS #-} PPGenericOverride Int8 where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Int8 -> MetaDoc ann
ppGenericOverride = forall ann. Int8 -> MetaDoc ann
metaDocInt8

instance {-# OVERLAPS #-} PPGenericOverride Int16 where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Int16 -> MetaDoc ann
ppGenericOverride = forall ann. Int16 -> MetaDoc ann
metaDocInt16

instance {-# OVERLAPS #-} PPGenericOverride Int32 where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Int32 -> MetaDoc ann
ppGenericOverride = forall ann. Int32 -> MetaDoc ann
metaDocInt32

instance {-# OVERLAPS #-} PPGenericOverride Int64 where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Int64 -> MetaDoc ann
ppGenericOverride = forall ann. Int64 -> MetaDoc ann
metaDocInt64

instance {-# OVERLAPS #-} PPGenericOverride () where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. () -> MetaDoc ann
ppGenericOverride = forall ann. () -> MetaDoc ann
metaDocUnit

instance {-# OVERLAPS #-} PPGenericOverride Bool where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Bool -> MetaDoc ann
ppGenericOverride = forall ann. Bool -> MetaDoc ann
metaDocBool

instance {-# OVERLAPS #-} PPGenericOverride Char where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Char -> MetaDoc ann
ppGenericOverride = forall ann. Char -> MetaDoc ann
metaDocChar

instance {-# OVERLAPS #-} PPGenericOverride a => PPGenericOverride (Ratio a) where
  {-# INLINABLE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Ratio a -> MetaDoc ann
ppGenericOverride (a
x :% a
y) =
    forall a ann. PPGenericOverride a => a -> MetaDoc ann
ppGenericOverride a
x forall a. Semigroup a => a -> a -> a
Semigroup.<> forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc Doc ann
"/" forall a. Semigroup a => a -> a -> a
<> forall a ann. PPGenericOverride a => a -> MetaDoc ann
ppGenericOverride a
y

instance {-# OVERLAPS #-} PPGenericOverride CallStack where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. CallStack -> MetaDoc ann
ppGenericOverride =
    forall ann. Doc ann -> MetaDoc ann
compositeMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ann. CallStack -> Doc ann
ppCallStack


instance {-# OVERLAPS #-} PPGenericOverride (Doc Void) where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Doc Void -> MetaDoc ann
ppGenericOverride =
    forall ann. Doc ann -> MetaDoc ann
compositeMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Void -> a
absurd

instance {-# OVERLAPS #-} PPGenericOverride String where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. [Char] -> MetaDoc ann
ppGenericOverride = forall ann. [Char] -> MetaDoc ann
stringMetaDoc

instance {-# OVERLAPS #-} PPGenericOverride T.Text where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Text -> MetaDoc ann
ppGenericOverride = forall ann. Text -> MetaDoc ann
strictTextMetaDoc

instance {-# OVERLAPS #-} PPGenericOverride TL.Text where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. Text -> MetaDoc ann
ppGenericOverride = forall ann. Text -> MetaDoc ann
lazyTextMetaDoc

instance {-# OVERLAPS #-} PPGenericOverride C8.ByteString where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. ByteString -> MetaDoc ann
ppGenericOverride = forall ann. ByteString -> MetaDoc ann
strictByteStringMetaDoc

instance {-# OVERLAPS #-} PPGenericOverride CL8.ByteString where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. ByteString -> MetaDoc ann
ppGenericOverride = forall ann. ByteString -> MetaDoc ann
lazyByteStringMetaDoc

instance {-# OVERLAPS #-} PPGenericOverride ShortBS.ShortByteString where
  {-# INLINE ppGenericOverride #-}
  ppGenericOverride :: forall ann. ShortByteString -> MetaDoc ann
ppGenericOverride = forall ann. ShortByteString -> MetaDoc ann
shortByteStringMetaDoc

instance {-# OVERLAPS #-} PPGenericOverride (ForeignPtr a)        where ppGenericOverride :: forall ann. ForeignPtr a -> MetaDoc ann
ppGenericOverride = forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a ann. Pretty a => a -> Doc ann
pretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> [Char]
show

instance {-# OVERLAPS #-} PPGenericOverride a => PPGenericOverride (TH.TyVarBndr a) where ppGenericOverride :: forall ann. TyVarBndr a -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from

instance {-# OVERLAPS #-} PPGenericOverride TH.OccName            where ppGenericOverride :: forall ann. OccName -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.NameFlavour        where ppGenericOverride :: forall ann. NameFlavour -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.PkgName            where ppGenericOverride :: forall ann. PkgName -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.NameSpace          where ppGenericOverride :: forall ann. NameSpace -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.ModName            where ppGenericOverride :: forall ann. ModName -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Name               where ppGenericOverride :: forall ann. Name -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.TyLit              where ppGenericOverride :: forall ann. TyLit -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Type               where ppGenericOverride :: forall ann. Kind -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.SourceUnpackedness where ppGenericOverride :: forall ann. SourceUnpackedness -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.SourceStrictness   where ppGenericOverride :: forall ann. SourceStrictness -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Bang               where ppGenericOverride :: forall ann. Bang -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Con                where ppGenericOverride :: forall ann. Con -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Lit                where ppGenericOverride :: forall ann. Lit -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Bytes              where ppGenericOverride :: forall ann. Bytes -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Stmt               where ppGenericOverride :: forall ann. Stmt -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Guard              where ppGenericOverride :: forall ann. Guard -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Body               where ppGenericOverride :: forall ann. Body -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Match              where ppGenericOverride :: forall ann. Match -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Range              where ppGenericOverride :: forall ann. Range -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Exp                where ppGenericOverride :: forall ann. Exp -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Pat                where ppGenericOverride :: forall ann. Pat -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Clause             where ppGenericOverride :: forall ann. Clause -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.DerivStrategy      where ppGenericOverride :: forall ann. DerivStrategy -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.DerivClause        where ppGenericOverride :: forall ann. DerivClause -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.FunDep             where ppGenericOverride :: forall ann. FunDep -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Overlap            where ppGenericOverride :: forall ann. Overlap -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Callconv           where ppGenericOverride :: forall ann. Callconv -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Safety             where ppGenericOverride :: forall ann. Safety -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Foreign            where ppGenericOverride :: forall ann. Foreign -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.FixityDirection    where ppGenericOverride :: forall ann. FixityDirection -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Fixity             where ppGenericOverride :: forall ann. Fixity -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Inline             where ppGenericOverride :: forall ann. Inline -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.RuleMatch          where ppGenericOverride :: forall ann. RuleMatch -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Phases             where ppGenericOverride :: forall ann. Phases -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.RuleBndr           where ppGenericOverride :: forall ann. RuleBndr -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.AnnTarget          where ppGenericOverride :: forall ann. AnnTarget -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Pragma             where ppGenericOverride :: forall ann. Pragma -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.TySynEqn           where ppGenericOverride :: forall ann. TySynEqn -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.FamilyResultSig    where ppGenericOverride :: forall ann. FamilyResultSig -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.InjectivityAnn     where ppGenericOverride :: forall ann. InjectivityAnn -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.TypeFamilyHead     where ppGenericOverride :: forall ann. TypeFamilyHead -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Role               where ppGenericOverride :: forall ann. Role -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.PatSynArgs         where ppGenericOverride :: forall ann. PatSynArgs -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.PatSynDir          where ppGenericOverride :: forall ann. PatSynDir -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Dec                where ppGenericOverride :: forall ann. Dec -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Info               where ppGenericOverride :: forall ann. Info -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
instance {-# OVERLAPS #-} PPGenericOverride TH.Specificity        where ppGenericOverride :: forall ann. Specificity -> MetaDoc ann
ppGenericOverride = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from

#if MIN_VERSION_template_haskell(2, 21, 0)
instance {-# OVERLAPS #-} PPGenericOverride TH.BndrVis            where ppGenericOverride = gpretty . from
#endif

instance {-# OVERLAPS #-}
  ( PPGenericOverride a
  , PPGenericOverride b
  ) => PPGenericOverride (a, b) where
  ppGenericOverride :: forall ann. (a, b) -> MetaDoc ann
ppGenericOverride (a
a, b
b) = forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall a b. (a -> b) -> a -> b
$ forall a ann. Pretty a => a -> Doc ann
pretty
    ( forall a. a -> PPGenericOverrideToPretty a
PPGenericOverrideToPretty a
a
    , forall a. a -> PPGenericOverrideToPretty a
PPGenericOverrideToPretty b
b
    )

instance {-# OVERLAPS #-}
  ( PPGenericOverride a
  , PPGenericOverride b
  , PPGenericOverride c
  ) => PPGenericOverride (a, b, c) where
  ppGenericOverride :: forall ann. (a, b, c) -> MetaDoc ann
ppGenericOverride (a
a, b
b, c
c) = forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall a b. (a -> b) -> a -> b
$ forall a ann. Pretty a => a -> Doc ann
pretty
    ( forall a. a -> PPGenericOverrideToPretty a
PPGenericOverrideToPretty a
a
    , forall a. a -> PPGenericOverrideToPretty a
PPGenericOverrideToPretty b
b
    , forall a. a -> PPGenericOverrideToPretty a
PPGenericOverrideToPretty c
c
    )

instance {-# OVERLAPS #-} PPGenericOverride v => PPGenericOverride (Maybe v) where
  ppGenericOverride :: forall ann. Maybe v -> MetaDoc ann
ppGenericOverride =
    forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> PPGenericOverrideToPretty a
PPGenericOverrideToPretty

instance {-# OVERLAPS #-} PPGenericOverride v => PPGenericOverride [v] where
  ppGenericOverride :: forall ann. [v] -> MetaDoc ann
ppGenericOverride =
    forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a ann. (a -> Doc ann) -> [a] -> Doc ann
ppListWith forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc

instance {-# OVERLAPS #-} (PPGenericOverride k, PPGenericOverride v) => PPGenericOverride [(k, v)] where
  ppGenericOverride :: forall ann. [(k, v)] -> MetaDoc ann
ppGenericOverride =
    forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWith forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc

instance {-# OVERLAPS #-} PPGenericOverride k => PPGenericOverride (NonEmpty k) where
  ppGenericOverride :: forall ann. NonEmpty k -> MetaDoc ann
ppGenericOverride =
    forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a ann. (a -> Doc ann) -> NonEmpty a -> Doc ann
ppNEWith forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc

instance {-# OVERLAPS #-} PPGenericOverride v => PPGenericOverride (Vector v) where
  ppGenericOverride :: forall ann. Vector v -> MetaDoc ann
ppGenericOverride =
    forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) a ann.
Vector v a =>
(a -> Doc ann) -> v a -> Doc ann
ppVectorWith forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc


instance {-# OVERLAPS #-} (PPGenericOverride k, PPGenericOverride v) => PPGenericOverride (Map k v) where
  ppGenericOverride :: forall ann. Map k v -> MetaDoc ann
ppGenericOverride =
    forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> Map k v -> Doc ann
ppMapWith forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc

instance {-# OVERLAPS #-} PPGenericOverride v => PPGenericOverride (Set v) where
  ppGenericOverride :: forall ann. Set v -> MetaDoc ann
ppGenericOverride =
    forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a ann. (a -> Doc ann) -> Set a -> Doc ann
ppSetWith forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc

instance {-# OVERLAPS #-} (PPGenericOverride k, PPGenericOverride v) => PPGenericOverride (Bimap k v) where
  ppGenericOverride :: forall ann. Bimap k v -> MetaDoc ann
ppGenericOverride =
    forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> Bimap k v -> Doc ann
ppBimapWith forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc

instance {-# OVERLAPS #-} PPGenericOverride IntSet.IntSet where
  ppGenericOverride :: forall ann. IntSet -> MetaDoc ann
ppGenericOverride =
    forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ann. (Int -> Doc ann) -> IntSet -> Doc ann
ppIntSetWith forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc

instance {-# OVERLAPS #-} PPGenericOverride v => PPGenericOverride (IntMap v) where
  ppGenericOverride :: forall ann. IntMap v -> MetaDoc ann
ppGenericOverride =
    forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ann a.
(Int -> Doc ann) -> (a -> Doc ann) -> IntMap a -> Doc ann
ppIntMapWith forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc

instance {-# OVERLAPS #-} PPGenericOverride v => PPGenericOverride (HashSet v) where
  ppGenericOverride :: forall ann. HashSet v -> MetaDoc ann
ppGenericOverride =
    forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a ann. (a -> Doc ann) -> HashSet a -> Doc ann
ppHashSetWith forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc

instance {-# OVERLAPS #-} (PPGenericOverride k, PPGenericOverride v) => PPGenericOverride (HashMap k v) where
  ppGenericOverride :: forall ann. HashMap k v -> MetaDoc ann
ppGenericOverride =
    forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> HashMap k v -> Doc ann
ppHashMapWith forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc forall a ann. PPGenericOverride a => a -> Doc ann
ppGenericOverrideDoc

instance {-# OVERLAPS #-} PPGenericOverride (f (g a)) => PPGenericOverride (Compose f g a) where
  ppGenericOverride :: forall ann. Compose f g a -> MetaDoc ann
ppGenericOverride =
    forall a ann. PPGenericOverride a => a -> MetaDoc ann
ppGenericOverride forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose


instance (GPretty f, GPretty g) => GPretty (f :*: g) where
  gpretty :: forall ix ann. (:*:) f g ix -> MetaDoc ann
gpretty (f ix
x :*: g ix
y) =
    forall ann. Doc ann -> MetaDoc ann
compositeMetaDoc forall a b. (a -> b) -> a -> b
$ forall ann. MetaDoc ann -> Doc ann
mdPayload MetaDoc ann
x' forall ann. Doc ann -> Doc ann -> Doc ann
<+> forall ann. MetaDoc ann -> Doc ann
mdPayload MetaDoc ann
y'
    where
      x' :: MetaDoc ann
x' = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty f ix
x
      y' :: MetaDoc ann
y' = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty g ix
y

instance GPretty x => GPretty (M1 D ('MetaData a b c d) x) where
  gpretty :: forall ix ann. M1 D ('MetaData a b c d) x ix -> MetaDoc ann
gpretty = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
unM1

instance GPretty x => GPretty (M1 S ('MetaSel 'Nothing b c d) x) where
  gpretty :: forall ix ann. M1 S ('MetaSel 'Nothing b c d) x ix -> MetaDoc ann
gpretty = forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
unM1

instance (KnownSymbol name, GFields x) => GPretty (M1 C ('MetaCons name _fixity 'False) x) where
  gpretty :: forall ix ann.
M1 C ('MetaCons name _fixity 'False) x ix -> MetaDoc ann
gpretty (M1 x ix
x) =
    forall ann. MetaDoc ann -> [MetaDoc ann] -> MetaDoc ann
constructorAppMetaDoc forall ann. MetaDoc ann
constructor forall ann. [MetaDoc ann]
args
    where
      constructor :: MetaDoc ann
      constructor :: forall ann. MetaDoc ann
constructor = forall ann. Doc ann -> MetaDoc ann
atomicMetaDoc forall a b. (a -> b) -> a -> b
$ forall a ann. Pretty a => a -> Doc ann
pretty forall a b. (a -> b) -> a -> b
$ forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> [Char]
symbolVal forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @name
      args :: [MetaDoc ann]
      args :: forall ann. [MetaDoc ann]
args = forall (t :: * -> *) a. Foldable t => t a -> [a]
toList forall a b. (a -> b) -> a -> b
$ forall {k} (a :: k -> *) (ix :: k) ann.
GFields a =>
a ix -> DList (MetaDoc ann)
gfields x ix
x

class GFields a where
  gfields :: a ix -> DList (MetaDoc ann)

instance GFields U1 where
  {-# INLINE gfields #-}
  gfields :: forall (ix :: k) ann. U1 ix -> DList (MetaDoc ann)
gfields = forall a b. a -> b -> a
const forall a. Monoid a => a
mempty

instance GPretty x => GFields (M1 S ('MetaSel a b c d) x) where
  {-# INLINABLE gfields #-}
  gfields :: forall ix ann. M1 S ('MetaSel a b c d) x ix -> DList (MetaDoc ann)
gfields = forall a. a -> DList a
DList.singleton forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
unM1

instance (GFields f, GFields g) => GFields (f :*: g) where
  {-# INLINABLE gfields #-}
  gfields :: forall (ix :: k) ann. (:*:) f g ix -> DList (MetaDoc ann)
gfields (f ix
f :*: g ix
g) = forall {k} (a :: k -> *) (ix :: k) ann.
GFields a =>
a ix -> DList (MetaDoc ann)
gfields f ix
f forall a. Semigroup a => a -> a -> a
<> forall {k} (a :: k -> *) (ix :: k) ann.
GFields a =>
a ix -> DList (MetaDoc ann)
gfields g ix
g


instance (KnownSymbol name, GCollectRecord f) => GPretty (M1 C ('MetaCons name _fixity 'True) f) where
  gpretty :: forall ix ann.
M1 C ('MetaCons name _fixity 'True) f ix -> MetaDoc ann
gpretty (M1 f ix
x) =
    forall ann. Doc ann -> MetaDoc ann
compositeMetaDoc forall a b. (a -> b) -> a -> b
$
      forall ann. Doc ann -> [MapEntry Text (Doc ann)] -> Doc ann
ppDictHeader
        (forall a ann. Pretty a => a -> Doc ann
pretty (forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> [Char]
symbolVal (forall {k} (t :: k). Proxy t
Proxy @name)))
        (forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall ann. MetaDoc ann -> Doc ann
mdPayload) (forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (forall {k} (a :: k -> *) (ix :: k) ann.
GCollectRecord a =>
a ix -> DList (MapEntry Text (MetaDoc ann))
gcollectRecord f ix
x)))

class GCollectRecord a where
  gcollectRecord :: a ix -> DList (MapEntry Text (MetaDoc ann))

instance (KnownSymbol name, GPretty a) => GCollectRecord (M1 S ('MetaSel ('Just name) su ss ds) a) where
  {-# INLINABLE gcollectRecord #-}
  gcollectRecord :: forall ix ann.
M1 S ('MetaSel ('Just name) su ss ds) a ix
-> DList (MapEntry Text (MetaDoc ann))
gcollectRecord (M1 a ix
x) =
    forall a. a -> DList a
DList.singleton ([Char] -> Text
T.pack (forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> [Char]
symbolVal (forall {k} (t :: k). Proxy t
Proxy @name)) forall k v. k -> v -> MapEntry k v
:-> forall (a :: * -> *) ix ann. GPretty a => a ix -> MetaDoc ann
gpretty a ix
x)

instance (GCollectRecord f, GCollectRecord g) => GCollectRecord (f :*: g) where
  {-# INLINABLE gcollectRecord #-}
  gcollectRecord :: forall (ix :: k) ann.
(:*:) f g ix -> DList (MapEntry Text (MetaDoc ann))
gcollectRecord (f ix
f :*: g ix
g) = forall {k} (a :: k -> *) (ix :: k) ann.
GCollectRecord a =>
a ix -> DList (MapEntry Text (MetaDoc ann))
gcollectRecord f ix
f forall a. Semigroup a => a -> a -> a
<> forall {k} (a :: k -> *) (ix :: k) ann.
GCollectRecord a =>
a ix -> DList (MapEntry Text (MetaDoc ann))
gcollectRecord g ix
g

instance GCollectRecord U1 where
  {-# INLINABLE gcollectRecord #-}
  gcollectRecord :: forall (ix :: k) ann. U1 ix -> DList (MapEntry Text (MetaDoc ann))
gcollectRecord = forall a b. a -> b -> a
const forall a. Monoid a => a
mempty