{-# LANGUAGE UndecidableInstances #-} -- due to type class design
{-# LANGUAGE AllowAmbiguousTypes  #-} -- due to type class design

module Generic.Data.Function.Contra.NonSum where

import Data.Functor.Contravariant

import GHC.Generics
import Generic.Data.Function.Contra.Constructor
  ( GContraC(gContraC)
  , GenericContra(type GenericContraF)
  )
import Generic.Data.Rep.Error

class GContraNonSum tag gf where gContraNonSum :: GenericContraF tag (gf p)

instance (Contravariant (GenericContraF tag), GContraC tag g)
  => GContraNonSum tag (C1 c g) where
    gContraNonSum :: forall (p :: k). GenericContraF tag (C1 c g p)
gContraNonSum = (M1 C c g p -> g p)
-> GenericContraF tag (g p) -> GenericContraF tag (M1 C c g p)
forall a' a.
(a' -> a) -> GenericContraF tag a -> GenericContraF tag a'
forall (f :: Type -> Type) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap M1 C c g p -> g p
forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
unM1 (forall (tag :: k) (gf :: k -> Type) (p :: k).
GContraC tag gf =>
GenericContraF tag (gf p)
forall {k} {k1} (tag :: k) (gf :: k1 -> Type) (p :: k1).
GContraC tag gf =>
GenericContraF tag (gf p)
gContraC @tag)

instance GContraNonSum tag (l :+: r) where gContraNonSum :: forall (p :: k). GenericContraF tag ((:+:) l r p)
gContraNonSum = [Char] -> GenericContraF tag ((:+:) l r p)
forall a. HasCallStack => [Char] -> a
error [Char]
eNoSum
instance GContraNonSum tag V1        where gContraNonSum :: forall (p :: k). GenericContraF tag (V1 p)
gContraNonSum = [Char] -> GenericContraF tag (V1 p)
forall a. HasCallStack => [Char] -> a
error [Char]
eNoEmpty