on master help sign in
Fix deep typed traversal
14abda5Csongor Kiss
src/Data/Generics/Product/Types.hs+11−2
@@ -53,11 +53,20 @@ instance
53class HasTypesDeep a s where
53class HasTypesDeep a s where
54 typesDeep :: Traversal' s a
54 typesDeep :: Traversal' s a
55
55
56+class Or a b where
57+ foldOr :: Applicative g => (a -> g a) -> b -> g b
58+
59+instance Or a a where
60+ foldOr f a = f a
61+
62+instance {-# OVERLAPPABLE #-} Or a b where
63+ foldOr _ = pure
64+
56instance
65instance
57− ( HasConstraints' ((~) a) s
66+ ( HasConstraints' (Or a) s
58 ) => HasTypesDeep a s where
67 ) => HasTypesDeep a s where
59
68
60− typesDeep f s = constraints' @((~) a) f s
69+ typesDeep f s = constraints' @(Or a) (foldOr f) s
61
70
62--------------------------------------------------------------------------------
71--------------------------------------------------------------------------------
63type family Primitive a :: Bool where
72type family Primitive a :: Bool where