Skip to content

Instantly share code, notes, and snippets.

@fumieval
Created August 30, 2019 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fumieval/058cca68eab1dcdc922e99d776acfd91 to your computer and use it in GitHub Desktop.
Save fumieval/058cca68eab1dcdc922e99d776acfd91 to your computer and use it in GitHub Desktop.
Can't derive Generic1 though
class FieldNamesB b where
bFieldNames :: IsString a => b (Const a)
default bFieldNames :: (Generic1 b, FieldNamesB (Rep b), IsString a) => b (Const a)
bFieldNames = to bFieldNames
instance FieldNamesB U1 where
bFieldNames = U1
instance (FieldNamesB t) => FieldNamesB (M1 C m t) where
bFieldNames = M1 bFieldNames
instance (FieldNamesB t) => FieldNamesB (M1 D m t) where
bFieldNames = M1 bFieldNames
instance (FieldNamesB f, FieldNamesB g) => FieldNamesB (f :*: g) where
bFieldNames = bFieldNames :*: bFieldNames
instance (m ~ 'MetaSel ('Just name) su ss ds, IsString a, KnownSymbol name) => FieldNamesB (M1 S m (Rec1 (Const a))) where
bFieldNames = M1 $ Rec1 $ Const $ fromString $ symbolVal (Proxy :: Proxy name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment