on master help sign in
tabulation: Add default implementation for traverseWithField in terms of tabulateFieldsA, add MINIMAL pragma.
commite7c7fb395ebf851e8422d5a99696a99930140b0b authorCale Gibbard <cgibbard@gmail.com> dateTue 28 May 2019, 14:25 (7 years ago) parent44bef50
1 file changed+6−2
lib/tabulation/src/Data/Tabulation.hs+6−2
lib/tabulation/src/Data/Tabulation.hs+6−2
@@ -8,10 +8,14 @@ import Control.Lens
88-- | 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.
99class HasFields a where
1010 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+
1115 tabulateFields :: (forall x. Field a x -> x) -> a
1216 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
1517 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))
1619 indexField :: a -> Field a x -> x
1720 indexField a f = a ^. fieldLens f
21+ {-# MINIMAL fieldLens, tabulateFieldsA #-}