Copyright | (c) Tom Harding 2019 |
---|---|
License | MIT |
Maintainer | tom.harding@habito.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
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, anddeconstruct
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) ]