module Data.Docs.Selectors where
import Data.Data (Proxy(..), TypeRep, Typeable, typeOf)
import GHC.Generics
class Selectors rep where
selectors :: Proxy rep -> [(String, TypeRep)]
instance Selectors f => Selectors (M1 D x f) where
selectors _ = selectors (Proxy :: Proxy f)
instance Selectors f => Selectors (M1 C x f) where
selectors _ = selectors (Proxy :: Proxy f)
instance (Selector s, Typeable t) => Selectors (M1 S s (K1 R t)) where
selectors _ =
let sel = selName (undefined :: M1 S s (K1 R t) ())
typ = typeOf (undefined :: t)
in if not (null sel)
then [( sel , typ )]
else []
instance (Selectors a, Selectors b) => Selectors (a :*: b) where
selectors _ = selectors (Proxy :: Proxy a) ++ selectors (Proxy :: Proxy b)
instance (Selectors a, Selectors b) => Selectors (a :+: b) where
selectors _ = selectors (Proxy :: Proxy a) ++ selectors (Proxy :: Proxy b)
instance Selectors U1 where
selectors _ = []