1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
module Data.Derive.UniplateTypeable where
{-
import "uniplate" Data.Generics.Uniplate.Typeable
example :: Custom
instance (Typeable a, PlateAll a to, Uniplate to, Typeable to) => PlateAll (Sample a) to where
plateAll (First) = plate First
plateAll (Second x1 x2) = plate Second |+ x1 |+ x2
plateAll (Third x1) = plate Third |+ x1
test :: Bool
instance (Typeable to, Uniplate to) => PlateAll Bool to where
plateAll False = plate False
plateAll True = plate True
test :: Either a b
instance (Typeable a, PlateAll a to, Typeable b, PlateAll b to, Typeable to, Uniplate to) => PlateAll (Either a b) to where
plateAll (Left x1) = plate Left |+ x1
plateAll (Right x1) = plate Right |+ x1
-}
import Data.Derive.DSL.HSE
-- GENERATED START
import Data.Derive.DSL.DSL
import Data.Derive.Internal.Derivation
makeUniplateTypeable :: Derivation
makeUniplateTypeable = derivationCustomDSL "UniplateTypeable" custom $
List [App "InstDecl" (List [List [App "ClassA" (List [App "UnQual"
(List [App "Ident" (List [String "Typeable"])]),List [App "TyVar"
(List [App "Ident" (List [String "a"])])]]),App "ClassA" (List [
App "UnQual" (List [App "Ident" (List [String "PlateAll"])]),List
[App "TyVar" (List [App "Ident" (List [String "a"])]),App "TyVar"
(List [App "Ident" (List [String "to"])])]]),App "ClassA" (List [
App "UnQual" (List [App "Ident" (List [String "Uniplate"])]),List
[App "TyVar" (List [App "Ident" (List [String "to"])])]]),App
"ClassA" (List [App "UnQual" (List [App "Ident" (List [String
"Typeable"])]),List [App "TyVar" (List [App "Ident" (List [String
"to"])])]])],App "UnQual" (List [App "Ident" (List [String
"PlateAll"])]),List [App "TyParen" (List [App "TyApp" (List [App
"TyCon" (List [App "UnQual" (List [App "Ident" (List [DataName])])
]),App "TyVar" (List [App "Ident" (List [String "a"])])])]),App
"TyVar" (List [App "Ident" (List [String "to"])])],List [App
"InsDecl" (List [App "FunBind" (List [MapCtor (App "Match" (List [
App "Ident" (List [String "plateAll"]),List [App "PParen" (List [
App "PApp" (List [App "UnQual" (List [App "Ident" (List [CtorName]
)]),MapField (App "PVar" (List [App "Ident" (List [Concat (List [
String "x",ShowInt FieldIndex])])]))])])],App "Nothing" (List []),
App "UnGuardedRhs" (List [Fold (App "InfixApp" (List [Tail,App
"QVarOp" (List [App "UnQual" (List [App "Symbol" (List [String
"|+"])])]),Head])) (Concat (List [Reverse (MapField (App "Var" (
List [App "UnQual" (List [App "Ident" (List [Concat (List [String
"x",ShowInt FieldIndex])])])]))),List [App "App" (List [App "Var"
(List [App "UnQual" (List [App "Ident" (List [String "plate"])])])
,App "Con" (List [App "UnQual" (List [App "Ident" (List [CtorName]
)])])])]]))]),App "BDecls" (List [List []])]))])])]])]
-- GENERATED STOP
custom (_,d) [InstDecl x1 _ x3 _ x5] = [InstDecl x1 x2 x3 x4 x5]
where
vars = dataDeclVars d
dd = (if null vars then id else TyParen) $ tyApps (tyCon $ dataDeclName d) (map tyVar vars)
x2 = concatMap f vars ++ [ClassA (qname x) [tyVar "to"] | x <- ["Typeable","Uniplate"]]
x4 = [dd, tyVar "to"]
f v = [ClassA (qname "Typeable") [tyVar v], ClassA (qname "PlateAll") [tyVar v, tyVar "to"]]
|