# Pastebin 415esCiO mkInstanceDeclaration :: String -> Name -> [VarBangType] -> Q [Dec] mkInstanceDeclaration tagName typeConstr fields = do fieldsExps <- fmap ListE $ forM fields $ \(fieldName, _, _) -> [e|($(stringE $ nameBase fieldName), $(varE fieldName) el & $(appTypeE $(varE $ mkName "field") $(strTyLit $ nameBase fieldName)) %~ (fmap) (pack . show))|] [d| instance Applicative f => Component2 f $(conT typeConstr) where tag2 = $(stringE tagName) attributes2 $(varP $ mkName "el") = $(pure fieldsExps) |]