on master help sign in
Add GHasParam instance for K1
f4073caCsongor Kiss
src/Data/Generics/Product/Internal/Param.hs+6
@@ -49,15 +49,21 @@ instance (GHasParam p l l' a b, GHasParam p r r' a b) => GHasParam p (l :+: r) (
49 gparam f (L1 l) = L1 <$> gparam @p f l
49 gparam f (L1 l) = L1 <$> gparam @p f l
50 gparam f (R1 r) = R1 <$> gparam @p f r
50 gparam f (R1 r) = R1 <$> gparam @p f r
51
51
52+-- the parameter we're looking for
52instance GHasParam p (Rec (param p) a) (Rec (param p) b) a b where
53instance GHasParam p (Rec (param p) a) (Rec (param p) b) a b where
53 gparam = recIso
54 gparam = recIso
54
55
56+-- other parameter
55instance {-# OVERLAPPABLE #-}
57instance {-# OVERLAPPABLE #-}
56 ( a ~ b
58 ( a ~ b
57 , p1 ~ p2
59 , p1 ~ p2
58 ) => GHasParam p (Rec p1 a) (Rec p2 b) c d where
60 ) => GHasParam p (Rec p1 a) (Rec p2 b) c d where
59 gparam _ = pure
61 gparam _ = pure
60
62
63+-- not a parameter
64+instance GHasParam p (K1 r a) (K1 r a) c d where
65+ gparam _ = pure
66+
61instance GHasParam p s t a b => GHasParam p (M1 m meta s) (M1 m meta t) a b where
67instance GHasParam p s t a b => GHasParam p (M1 m meta s) (M1 m meta t) a b where
62 gparam f (M1 x) = M1 <$> gparam @p f x
68 gparam f (M1 x) = M1 <$> gparam @p f x
63
69
test/Spec.hs+2−2
@@ -92,8 +92,8 @@ data Sum2 = A2 Char | B2 Int deriving (Generic, Show)
92
92
93data Sum3 a b c
93data Sum3 a b c
94 = A3 a a
94 = A3 a a
95− | B3 b a a b
95+ | B3 String b a a b
96− | C3 c a
96+ | C3 c a Int
97 deriving Generic
97 deriving Generic
98
98
99-- TODO: these compile, but aren't wired in to inspection-testing yet
99-- TODO: these compile, but aren't wired in to inspection-testing yet