higgledy-0.3.1.0: Partial types as a type constructor.

Copyright(c) Tom Harding 2019
LicenseMIT
Maintainertom.harding@habito.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Data.Generic.HKD.Types

Description

 
Synopsis

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) [])
(,) [] []

Constructors

HKD 

Fields

Instances
(ProductB (HKD structure), ConstraintsB (HKD structure), GProductBC (Rep structure)) => ProductBC (HKD structure :: (Type -> Type) -> Type) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

bdicts :: AllB c (HKD structure) => HKD structure (Dict c) #

(FunctorB (HKD structure), GConstraintsB (Rep structure), GAllBC (Rep structure)) => ConstraintsB (HKD structure :: (Type -> Type) -> Type) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Associated Types

type AllB c (HKD structure) :: Constraint #

Methods

baddDicts :: AllB c (HKD structure) => HKD structure f -> HKD structure (Product (Dict c) f) #

(FunctorB (HKD structure), GProductB (Rep structure)) => ProductB (HKD structure :: (Type -> Type) -> Type) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

bprod :: HKD structure f -> HKD structure g -> HKD structure (Product f g) #

buniq :: (forall (a :: k). f a) -> HKD structure f #

(FunctorB (HKD structure), GTraversableB (Rep structure)) => TraversableB (HKD structure :: (Type -> Type) -> Type) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

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 # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

bmap :: (forall (a :: k). f a -> g a) -> HKD structure f -> HKD structure g #

(Eq tuple, Generic xs, Tuple f xs tuple) => Eq (HKD xs f) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

(==) :: HKD xs f -> HKD xs f -> Bool #

(/=) :: HKD xs f -> HKD xs f -> Bool #

(Ord tuple, Generic xs, Tuple f xs tuple) => Ord (HKD xs f) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

compare :: HKD xs f -> HKD xs f -> Ordering #

(<) :: HKD xs f -> HKD xs f -> Bool #

(<=) :: HKD xs f -> HKD xs f -> Bool #

(>) :: HKD xs f -> HKD xs f -> Bool #

(>=) :: HKD xs f -> HKD xs f -> Bool #

max :: HKD xs f -> HKD xs f -> HKD xs f #

min :: HKD xs f -> HKD xs f -> HKD xs f #

(Generic structure, GShow True (HKD_ f structure)) => Show (HKD structure f) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

showsPrec :: Int -> HKD structure f -> ShowS #

show :: HKD structure f -> String #

showList :: [HKD structure f] -> ShowS #

(Contravariant (HKD_ f structure), Functor (HKD_ f structure)) => Generic (HKD structure f) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Associated Types

type Rep (HKD structure f) :: Type -> Type #

Methods

from :: HKD structure f -> Rep (HKD structure f) x #

to :: Rep (HKD structure f) x -> HKD structure f #

(Semigroup tuple, Generic xs, Tuple f xs tuple) => Semigroup (HKD xs f) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

(<>) :: HKD xs f -> HKD xs f -> HKD xs f #

sconcat :: NonEmpty (HKD xs f) -> HKD xs f #

stimes :: Integral b => b -> HKD xs f -> HKD xs f #

(Monoid tuple, Generic xs, Tuple f xs tuple) => Monoid (HKD xs f) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

mempty :: HKD xs f #

mappend :: HKD xs f -> HKD xs f -> HKD xs f #

mconcat :: [HKD xs f] -> HKD xs f #

(Generic structure, Function tuple, Tuple f structure tuple) => Function (HKD structure f) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

function :: (HKD structure f -> b) -> HKD structure f :-> b #

(Arbitrary tuple, GToTuple (HKD_ f structure) tuple) => Arbitrary (HKD structure f) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

arbitrary :: Gen (HKD structure f) #

shrink :: HKD structure f -> [HKD structure f] #

(CoArbitrary tuple, GToTuple (HKD_ f structure) tuple) => CoArbitrary (HKD structure f) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

coarbitrary :: HKD structure f -> Gen b -> Gen b #

type AllB (c :: Type -> Constraint) (HKD structure :: (Type -> Type) -> Type) Source # 
Instance details

Defined in Data.Generic.HKD.Types

type AllB (c :: Type -> Constraint) (HKD structure :: (Type -> Type) -> Type)
type Rep (HKD structure f) Source # 
Instance details

Defined in Data.Generic.HKD.Types

type Rep (HKD structure f) = HKD_ f structure

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.

Equations

GHKD_ f (M1 index meta inner) = M1 index meta (GHKD_ f inner) 
GHKD_ f (left :*: right) = GHKD_ f left :*: GHKD_ f right 
GHKD_ f (K1 index value) = K1 index (f value) 
GHKD_ f (left :+: right) = GHKD_ f left :+: GHKD_ f right 

class Tuple (f :: Type -> Type) (structure :: Type) (tuple :: Type) | f structure -> tuple where Source #

Methods

toTuple :: HKD structure f -> tuple Source #

fromTuple :: tuple -> HKD structure f Source #

Instances
(Generic structure, GToTuple (HKD_ f structure) tuple) => Tuple f structure tuple Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

toTuple :: HKD structure f -> tuple Source #

fromTuple :: tuple -> HKD structure f Source #