module Generic where

import GHC.Generics
import ClassyPrelude.Yesod
import Data.Kind (Type)

constrName :: (HasConstructor (Rep a), Generic a)=> a -> String
constrName :: forall a. (HasConstructor (Rep a), Generic a) => a -> String
constrName = forall (f :: * -> *) x. HasConstructor f => f x -> String
genericConstrName forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a x. Generic a => a -> Rep a x
from 

class HasConstructor (f :: Type -> Type) where
  genericConstrName :: f x -> String

instance HasConstructor f => HasConstructor (D1 c f) where
  genericConstrName :: forall x. D1 c f x -> String
genericConstrName (M1 f x
x) = forall (f :: * -> *) x. HasConstructor f => f x -> String
genericConstrName f x
x

instance (HasConstructor x, HasConstructor y) => HasConstructor (x :+: y) where
  genericConstrName :: forall x. (:+:) x y x -> String
genericConstrName (L1 x x
l) = forall (f :: * -> *) x. HasConstructor f => f x -> String
genericConstrName x x
l
  genericConstrName (R1 y x
r) = forall (f :: * -> *) x. HasConstructor f => f x -> String
genericConstrName y x
r

instance Constructor c => HasConstructor (C1 c f) where
  genericConstrName :: forall x. C1 c f x -> String
genericConstrName C1 c f x
x = forall {k} (c :: k) k1 (t :: k -> (k1 -> *) -> k1 -> *)
       (f :: k1 -> *) (a :: k1).
Constructor c =>
t c f a -> String
conName C1 c f x
x