numberedArgs :: [a] -> Q [Name]
numberedArgs = zipWithM (\i _->newName $ "f" ++ show i) [0 :: Int ..]
+adtFieldName :: Name -> Int -> Name
+adtFieldName consName idx = mkName $ map toLower (stringName consName) ++ "f" ++ show idx
+
data Field = Field { fname :: Name, ffresh :: Name, ftype :: Type }
toNameType :: Con -> Q [Field]
toNameType (NormalC consName fs) = numberedArgs fs
- >>= \nfs->pure [Field (mkName $ map toLower (stringName consName) ++ "f" ++ show i) nf t | (_, t) <- fs | nf <- nfs | i <- [0 :: Int ..]]
+ >>= \nfs->pure [Field (adtFieldName consName i) nf t | (_, t) <- fs | nf <- nfs | i <- [0 :: Int ..]]
toNameType (RecC _ fs) = numberedArgs fs
>>= \nfs->pure [Field n nf t | (n, _, t)<-fs | nf <- nfs]
toNameType c = fail $ "Unsupported constructor type: " ++ show c