espial-0.0.39: src/Generic.hs
module Generic where
import ClassyPrelude.Yesod
import Data.Kind (Type)
import GHC.Generics
constrName :: (HasConstructor (Rep a), Generic a) => a -> String
constrName = genericConstrName . from
class HasConstructor (f :: Type -> Type) where
genericConstrName :: f x -> String
instance (HasConstructor f) => HasConstructor (D1 c f) where
genericConstrName (M1 x) = genericConstrName x
instance (HasConstructor x, HasConstructor y) => HasConstructor (x :+: y) where
genericConstrName (L1 l) = genericConstrName l
genericConstrName (R1 r) = genericConstrName r
instance (Constructor c) => HasConstructor (C1 c f) where
genericConstrName x = conName x