on master help sign in
tabulation: Add default implementation for traverseWithField in terms of tabulateFieldsA, add MINIMAL pragma.
e7c7fb3Cale Gibbard
lib/tabulation/src/Data/Tabulation.hs+6−2
@@ -8,10 +8,14 @@ import Control.Lens
8-- | This is a class for record types whose fields can be enumerated by an associated GADT. It's closely related to the concept of a representable functor, except without the functor part, and the fields are not all the same type.
8-- | This is a class for record types whose fields can be enumerated by an associated GADT. It's closely related to the concept of a representable functor, except without the functor part, and the fields are not all the same type.
9class HasFields a where
9class HasFields a where
10 type Field a :: * -> *
10 type Field a :: * -> *
11+
12+ fieldLens :: Field a x -> Lens' a x
13+ tabulateFieldsA :: Applicative f => (forall x. Field a x -> f x) -> f a
14+
11 tabulateFields :: (forall x. Field a x -> x) -> a
15 tabulateFields :: (forall x. Field a x -> x) -> a
12 tabulateFields f = runIdentity (tabulateFieldsA (Identity . f))
16 tabulateFields f = runIdentity (tabulateFieldsA (Identity . f))
13− tabulateFieldsA :: Applicative f => (forall x. Field a x -> f x) -> f a
14− fieldLens :: Field a x -> Lens' a x
15 traverseWithField :: Applicative m => (forall x. Field a x -> x -> m x) -> a -> m a
17 traverseWithField :: Applicative m => (forall x. Field a x -> x -> m x) -> a -> m a
18+ traverseWithField t r = tabulateFieldsA (\f -> t f (indexField r f))
16 indexField :: a -> Field a x -> x
19 indexField :: a -> Field a x -> x
17 indexField a f = a ^. fieldLens f
20 indexField a f = a ^. fieldLens f
21+ {-# MINIMAL fieldLens, tabulateFieldsA #-}