- data Field c a
- record :: String -> Q [Dec] -> Q [Dec]
- class SomeField f where
- modField :: SomeField f => f s a -> (a -> a) -> s -> s
- data FieldPath f g b a c
- (//) :: (SomeField f, SomeField g) => f a b -> g b c -> FieldPath f g b a c
- getf :: (MonadState s m, SomeField f) => f s a -> m a
- putf :: (MonadState s m, SomeField f) => f s a -> a -> m ()
- modf :: (MonadState s m, SomeField f) => f s a -> (a -> a) -> m ()
- enter :: (MonadState s m, SomeField f) => f s a -> State a b -> m b
- enterT :: (Monad m, SomeField f) => f s a -> StateT a m b -> StateT s m b

# Documentation

record :: String -> Q [Dec] -> Q [Dec]Source

Modify the given 'data' or 'newtype' declaration so that all field names are prefixed with an underscore followed by the given string, and generate declarations of field descriptors for all fields, each bound to the corresponding field name prefixed with the given string (but no underscore).

Example usage (this goes at the top level of a module):

record "foo" [d| data Foo = Foo { bar :: Int, baz :: Int } |]

Note: the second parameter is Q [Dec] because this is what the [d| |] form returns, which is the most convenient way to use this function. However, the list must contain exactly one declaration, and it must be a 'data' or 'newtype' declaration.

Note: in addition to adding the given prefix to each name, the first character of the original name is capitalized.

The class of field descriptors. A descriptor of type 'f a b' refers to a
field of type `b`

nested somewhere within a record of type `a`

.

modField :: SomeField f => f s a -> (a -> a) -> s -> sSource

Modify the value of a field by applying a function.

(//) :: (SomeField f, SomeField g) => f a b -> g b c -> FieldPath f g b a cSource

Join two field descriptors into a compound.
`//`

is left-associative with precedence level 9.

getf :: (MonadState s m, SomeField f) => f s a -> m aSource

Get the value of a field from the state.

putf :: (MonadState s m, SomeField f) => f s a -> a -> m ()Source

Put a value into a field in the state.

modf :: (MonadState s m, SomeField f) => f s a -> (a -> a) -> m ()Source

Modify the value of a field in the state by applying a function.

enter :: (MonadState s m, SomeField f) => f s a -> State a b -> m bSource

Enter the context of a field and run a stateful computation there.