higgledy-0.3.0.0: Partial types as a type constructor.

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

Data.Generic.HKD.Construction

Description

 
Synopsis

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)
>>> construct (mempty @(HKD (Int, Bool) Last))
Last {getLast = Nothing}

We can also deconstruct a tuple into a partial structure:

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

These two methods also satisfy the round-tripping property:

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

Methods

construct :: HKD structure f -> f structure Source #

deconstruct :: structure -> HKD structure f Source #

Instances
(Functor f, Generic structure, GConstruct f (Rep structure)) => Construct f structure Source # 
Instance details

Defined in Data.Generic.HKD.Construction

Methods

construct :: HKD structure f -> f structure Source #

deconstruct :: structure -> HKD structure f Source #