-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
Being able to obtain field names of a record is pretty useful. The following code works but unfortunately GHC can't derive Generic1 instances of higher-kinded types... Do you think barbies' hacks can be applied here?
class FieldNamesB b where
bfieldNames :: b (Const String)
instance FieldNamesB U1 where
bfieldNames = U1
instance (FieldNamesB f, FieldNamesB g) => FieldNamesB (f :*: g) where
bfieldNames = bfieldNames :*: bfieldNames
instance (FieldNamesB t, c ~ 'MetaSel ('Just name) su ss dl, KnownSymbol name, t ~ Const String) => FieldNamesB (M1 S c t) where
bfieldNames = M1 (Const (fromString (symbolVal (Proxy :: Proxy name))))
instance (FieldNamesB t) => FieldNamesB (M1 C c t) where
bfieldNames = M1 bfieldNames
instance (FieldNamesB t) => FieldNamesB (M1 D c t) where
bfieldNames = M1 bfieldNamesMetadata
Metadata
Assignees
Labels
No labels