Copyright | (c) Tom Harding 2019 |
---|---|

License | MIT |

Maintainer | tom.harding@habito.com |

Stability | experimental |

Safe Haskell | None |

Language | Haskell2010 |

## Synopsis

- class Construct (f :: Type -> Type) (structure :: Type) where
- construct :: HKD structure f -> f structure
- deconstruct :: structure -> HKD structure f

- class GConstruct (f :: Type -> Type) (rep :: Type -> Type) where
- gconstruct :: GHKD_ f rep p -> f (rep p)
- gdeconstruct :: rep p -> GHKD_ f rep p

# Documentation

class Construct (f :: Type -> Type) (structure :: Type) where Source #

When working with the HKD representation, it is useful to have a way to convert to and from our original type. To do this, we can:

`construct`

the original type from our HKD representation, and`deconstruct`

the original type*into*our HKD representation.

As an example, we can try (unsuccessfully) to construct an `(Int, Bool)`

tuple from an unpopulated partial structure.

`>>>`

`:set -XTypeApplications`

`>>>`

`import Data.Monoid (Last)`

`>>>`

Last {getLast = Nothing}`construct (mempty @(HKD (Int, Bool) Last))`

We can also *deconstruct* a tuple into a partial structure:

`>>>`

(,) ["Hello"] [True]`deconstruct @[] ("Hello", True)`

These two methods also satisfy the round-tripping property:

construct (deconstruct x) == [ x :: (Int, Bool, String) ]

class GConstruct (f :: Type -> Type) (rep :: Type -> Type) where Source #

gconstruct :: GHKD_ f rep p -> f (rep p) Source #

gdeconstruct :: rep p -> GHKD_ f rep p Source #

## Instances

Applicative f => GConstruct f (K1 index inner :: Type -> Type) Source # | |

Defined in Data.Generic.HKD.Construction | |

(Applicative f, GConstruct f left, GConstruct f right) => GConstruct f (left :*: right) Source # | |

Defined in Data.Generic.HKD.Construction | |

(Functor f, GConstruct f inner) => GConstruct f (M1 index meta inner) Source # | |

Defined in Data.Generic.HKD.Construction |