{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

{-# OPTIONS -Wno-unticked-promoted-constructors #-}

-- | "GHC.Generics" definition of 'mempty'
module Data.DerivingVia.GHC.Generics.Monoid (
  GMonoid (..),
)
where

import GHC.Generics
import GHC.TypeLits

class GMonoid rep where
  gmempty :: rep x

instance Monoid c => GMonoid (K1 i c) where
  gmempty :: forall x. K1 i c x
gmempty = forall k i c (p :: k). c -> K1 i c p
K1 forall a. Monoid a => a
mempty

instance GMonoid f => GMonoid (M1 i c f) where
  gmempty :: forall x. M1 i c f x
gmempty = forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 forall (rep :: * -> *) x. GMonoid rep => rep x
gmempty

instance GMonoid V1 where
  gmempty :: forall x. V1 x
gmempty = forall a. HasCallStack => [Char] -> a
error [Char]
"GMonoid V1"

instance GMonoid U1 where
  gmempty :: forall x. U1 x
gmempty = forall k (p :: k). U1 p
U1

instance (GMonoid l, GMonoid r) => GMonoid (l :*: r) where
  gmempty :: forall x. (:*:) l r x
gmempty = forall (rep :: * -> *) x. GMonoid rep => rep x
gmempty forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: forall (rep :: * -> *) x. GMonoid rep => rep x
gmempty

instance
  TypeError
    ( Text "No Generics definition of "
        :<>: ShowType Monoid
        :<>: Text " for types with multiple constructors "
        :<>: ShowType (l :+: r)
    ) =>
  GMonoid (l :+: r)
  where
  gmempty :: forall x. (:+:) l r x
gmempty = forall a. HasCallStack => [Char] -> a
error [Char]
"GMonoid :+:"