-> case dec of
DataD _ _ tyvars _ constructors _
-> sequence
- [ mkDerivation tyvars
- , mkConstructorClasses tyvars constructors
+ [ {-mkDerivation tyvars
+ ,-}mkConstructorClasses tyvars constructors
, mkPrinterInstances constructors
, mkCompilerInstances constructors
]
_
-> fail "mkConsClass only supports types"
where
- mkDerivation :: [TyVarBndr] -> DecQ
- mkDerivation tyvars = let names = (map (VarT . getNameTyVarBndr) tyvars) in pure $
- InstanceD Nothing
- [ConT (mkName "Serialise") `AppT` t | t <- names]
- (ConT (mkName "Serialise") `AppT` foldl AppT (ConT typename) names)
- []
+-- mkDerivation :: [TyVarBndr] -> DecQ
+-- mkDerivation tyvars = let names = (map (VarT . getNameTyVarBndr) tyvars) in pure $
+-- InstanceD Nothing
+-- [ConT (mkName "Serialise") `AppT` t | t <- names]
+-- (ConT (mkName "Serialise") `AppT` foldl AppT (ConT typename) names)
+-- []
mkConstructorClasses :: [TyVarBndr] -> [Con] -> DecQ
mkConstructorClasses tyvars constructors = do
mkSelectorClassMember (NormalC consName fs)
= mapM (uncurry mkSelectorClassMemberForField)
$ zipWith (\(_, t) i->(mkName $ map toLower (stringName consName) ++ "f" ++ show i, t)) fs [0 :: Int ..]
- mkSelectorClassMember (RecC _ fs)
- = mapM (uncurry mkSelectorClassMemberForField) [(n, t)|(n, _, t)<-fs]
+ mkSelectorClassMember (RecC consName fs)
+ = (++) <$> mapM (uncurry mkSelectorClassMemberForField) [(n, t)|(n, _, t)<-fs]
+ <*> mapM (uncurry mkSelectorClassMemberForField)
+ (zipWith (\(_, _, t) i->(mkName $ map toLower (stringName consName) ++ "f" ++ show i, t)) fs [0 :: Int ..])
+
mkSelectorClassMember t
= fail $ "mkConsClass not supported for types such as: " ++ show t
])
<*> mapM mkPrinterSelector
(zipWith (\_ i->map toLower (stringName consName) ++ "f" ++ show i) fs [0 :: Int ..])
- mkPrinterInstance (RecC name fs)
+ mkPrinterInstance (RecC consName fs)
= let args = map mkName $ numberedArgs fs
- in (:) <$> pure (FunD (constructorName name)
+ in (:) <$> pure (FunD (constructorName consName)
[Clause
(map VarP args)
(NormalB $
)
[]
])
- <*> mapM mkPrinterSelector [occString occ | (Name occ _, _, _)<-fs]
+ <*> ((++)
+ <$> mapM mkPrinterSelector [occString occ | (Name occ _, _, _)<-fs]
+ <*> mapM mkPrinterSelector
+ (zipWith (\_ i->map toLower (stringName consName) ++ "f" ++ show i) fs [0 :: Int ..])
+ )
mkPrinterInstance t = fail $ "mkConsClass not supported for types such as: " ++ show t
mkPrinterSelector :: String -> Q Dec
<*> mapM (uncurry mkCompilerSelector) (zip [0..] [map toLower (stringName consName) ++ f | f<-numberedArgs fs])
mkCompilerInstance (RecC consName fs) consnum = (:)
<$> mkCompilerInstanceForName consName consnum [occString occ | (Name occ _, _, _) <- fs]
- <*> mapM (uncurry mkCompilerSelector) (zip [0..] [occString occ | (Name occ _, _, _) <- fs])
+ <*> ((++)
+ <$> mapM (uncurry mkCompilerSelector) (zip [0..] [occString occ | (Name occ _, _, _) <- fs])
+ <*> mapM (uncurry mkCompilerSelector) (zip [0..] [map toLower (stringName consName) ++ f | f<-numberedArgs fs])
+ )
mkCompilerInstance t _ = fail $ "mkConsClass not supported for types such as: " ++ show t
mkCompilerInstanceForName :: Name -> Int -> [String] -> DecQ