Copyright | (c) Tom Harding 2019 |
---|---|
License | MIT |
Maintainer | tom.harding@habito.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- newtype HKD (structure :: Type) (f :: Type -> Type) = HKD {}
- type HKD_ (f :: Type -> Type) (structure :: Type) = GHKD_ f (Rep structure)
- type family GHKD_ (f :: Type -> Type) (rep :: Type -> Type) = (output :: Type -> Type) | output -> f rep where ...
- class Tuple (f :: Type -> Type) (structure :: Type) (tuple :: Type) | f structure -> tuple where
Documentation
newtype HKD (structure :: Type) (f :: Type -> Type) Source #
Higher-kinded data (HKD) is the design pattern in which every field in our
type is wrapped in some functor f
:
data User f = User { name :: f String , age :: f Int }
Depending on the functor, we can get different behaviours: with Maybe
, we
get a partial structure; with Validation
, we get a piecemeal validator;
and so on. The HKD
newtype allows us to lift any type into an HKD-style
API via its generic representation.
>>>
:set -XDeriveGeneric -XTypeApplications
>>>
:{
data User = User { name :: String, age :: Int } deriving Generic :}
The HKD
type is indexed by our choice of functor and the structure we're
lifting. In other words, we can define a synonym for our behaviour:
>>>
import Data.Monoid (Last (..))
>>>
type Partial a = HKD a Last
... and then we're ready to go!
>>>
mempty @(Partial User)
User {name = Last {getLast = Nothing}, age = Last {getLast = Nothing}}
>>>
mempty @(HKD (Int, Bool) [])
(,) [] []
Instances
(ProductB (HKD structure), ConstraintsB (HKD structure), GProductBC (Rep structure)) => ProductBC (HKD structure :: (Type -> Type) -> Type) Source # | |
(FunctorB (HKD structure), GConstraintsB (Rep structure), GAllBC (Rep structure)) => ConstraintsB (HKD structure :: (Type -> Type) -> Type) Source # | |
(FunctorB (HKD structure), GProductB (Rep structure)) => ProductB (HKD structure :: (Type -> Type) -> Type) Source # | |
(FunctorB (HKD structure), GTraversableB (Rep structure)) => TraversableB (HKD structure :: (Type -> Type) -> Type) Source # | |
Defined in Data.Generic.HKD.Types btraverse :: Applicative t => (forall (a :: k). f a -> t (g a)) -> HKD structure f -> t (HKD structure g) # | |
GFunctorB (Rep structure) => FunctorB (HKD structure :: (Type -> Type) -> Type) Source # | |
Defined in Data.Generic.HKD.Types | |
(Eq tuple, Generic xs, Tuple f xs tuple) => Eq (HKD xs f) Source # | |
(Ord tuple, Generic xs, Tuple f xs tuple) => Ord (HKD xs f) Source # | |
Defined in Data.Generic.HKD.Types | |
(Generic structure, GShow True (HKD_ f structure)) => Show (HKD structure f) Source # | |
(Semigroup tuple, Generic xs, Tuple f xs tuple) => Semigroup (HKD xs f) Source # | |
(Monoid tuple, Generic xs, Tuple f xs tuple) => Monoid (HKD xs f) Source # | |
(Generic structure, Function tuple, Tuple f structure tuple) => Function (HKD structure f) Source # | |
(Arbitrary tuple, GToTuple (HKD_ f structure) tuple) => Arbitrary (HKD structure f) Source # | |
(CoArbitrary tuple, GToTuple (HKD_ f structure) tuple) => CoArbitrary (HKD structure f) Source # | |
Defined in Data.Generic.HKD.Types coarbitrary :: HKD structure f -> Gen b -> Gen b # | |
type AllB (c :: Type -> Constraint) (HKD structure :: (Type -> Type) -> Type) Source # | |
Defined in Data.Generic.HKD.Types |
type HKD_ (f :: Type -> Type) (structure :: Type) = GHKD_ f (Rep structure) Source #
Calculate the "partial representation" of a type.
type family GHKD_ (f :: Type -> Type) (rep :: Type -> Type) = (output :: Type -> Type) | output -> f rep where ... Source #
Calculate the "partial representation" of a generic rep.