| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
RecordOperations
Synopsis
- type MapRecord f a b = GenMapRecord f a (Rep b ())
- class MapField a where
- mapRecord :: forall b f a. (Generic b, MapRecord f a b) => (forall c. c -> f c) -> a -> b
- type RecordSubSet a b = GenRecordSubSet a (Rep b ())
- recordSubSet :: forall b a. (Generic b, RecordSubSet a b) => a -> b
Documentation
type MapRecord f a b = GenMapRecord f a (Rep b ()) Source #
the constraint determines that MapRecord f a ba can be
converted into b, using the newtype f.
mapRecord :: forall b f a. (Generic b, MapRecord f a b) => (forall c. c -> f c) -> a -> b Source #
map a polymorphic function over a record. The function should be
implemented as a newtype which is an instance of the MapField
class, with corresponding type family Mapped. Pass the newtype
constructor to the mapRecord function. For example to "functorize" all fields:
data Foo = Foo
{ foo :: Int
, bar :: String
} deriving (Show, Generic)
data FunctorFoo f = FunctorFoo
{ foo :: f Int
, bar :: f String
} deriving (Generic)
newtype ToFunctor (f :: * -> *) a = ToFunctor a
instance Applicative f => MapField (ToFunctor f a) where
type Mapped (ToFunctor f a) = f a
mapField (ToFunctor x) = pure x
functorize :: Applicative f => Foo -> FunctorFoo f
functorize = mapRecord ToFunctor
type RecordSubSet a b = GenRecordSubSet a (Rep b ()) Source #
The constraint determines that the fields of
RecordSubSet a bb are a subset of the fields of a.
recordSubSet :: forall b a. (Generic b, RecordSubSet a b) => a -> b Source #
get subset of a record. For example:
data Foo = Foo
{ foo :: Int
, bar :: String
} deriving (Show, Generic)
data Bar = Bar
{ bar :: String
} deriving (Show, Generic)
subFoo :: Foo -> Bar
subFoo = recordSubSet