higgledy-0.4.2.1: 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

Instances details
(FunctorB (HKD structure), GApplicativeB (Rep structure)) => ApplicativeB (HKD structure :: (Type -> Type) -> TYPE LiftedRep) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

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

bprod :: forall (f :: k -> Type) (g :: k -> Type). HKD structure f -> HKD structure g -> HKD structure (Product f g) #

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

Defined in Data.Generic.HKD.Types

Associated Types

type AllB c (HKD structure) #

Methods

baddDicts :: forall (c :: k -> Constraint) (f :: k -> Type). AllB c (HKD structure) => HKD structure f -> HKD structure (Product (Dict c) f) #

GFunctorB (Rep structure) => FunctorB (HKD structure :: (Type -> Type) -> TYPE LiftedRep) Source # 
Instance details

Defined in Data.Generic.HKD.Types

Methods

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

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

Defined in Data.Generic.HKD.Types

Methods

btraverse :: Applicative e => (forall (a :: k). f a -> e (g a)) -> HKD structure f -> e (HKD structure g) #

(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 #

(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 #

(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 #

(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 #

(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 #

(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 #

(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 #

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

Defined in Data.Generic.HKD.Types

type AllB (c :: Type -> Constraint) (HKD structure :: (Type -> Type) -> TYPE LiftedRep)
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 #

Often, we can get instances by using an HKD type's isomorphism with a certain size of tuple. This class witnesses the isomorphism with a certain tuple (specifically a nested tree of pairs) to allow us to derive "via" these shapes.

Methods

toTuple :: HKD structure f -> tuple Source #

fromTuple :: tuple -> HKD structure f Source #

Instances

Instances details
(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 #