on decrease-android-validity help sign in
obelisk/lib/tabulation/src/Data/Tabulation.hs
21 lines 897 B history raw
1{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE RankNTypes #-}
4module Data.Tabulation where
6import 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.
9class HasFields a where
10 type Field a :: * -> *
12 fieldLens :: Field a x -> Lens' a x
13 tabulateFieldsA :: Applicative f => (forall x. Field a x -> f x) -> f a
15 tabulateFields :: (forall x. Field a x -> x) -> a
16 tabulateFields f = runIdentity (tabulateFieldsA (Identity . f))
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))
19 indexField :: a -> Field a x -> x
20 indexField a f = a ^. fieldLens f
21 {-# MINIMAL fieldLens, tabulateFieldsA #-}