higgledy-0.2.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.Position

Description

 
Synopsis

Documentation

class HasPosition' (index :: Nat) (f :: Type -> Type) (structure :: Type) (focus :: Type) | index f structure -> focus where Source #

Product types without named fields can't be addressed by field name (for very obvious reason), so we instead need to address them with their "position" index. This is a one-indexed type-applied natural:

>>> import Control.Lens ((^.))
>>> :t mempty @(HKD (Int, String) []) ^. position @1
mempty @(HKD (Int, String) []) ^. position @1 :: [Int]

As we're using the wonderful generic-lens library under the hood, we also get some beautiful error messages when things go awry:

>>> import Data.Generic.HKD.Construction
>>> deconstruct ("Hello", True) ^. position @4
...
... error:
... • The type ([Char], Bool) does not contain a field at position 4
...

Methods

position :: Lens' (HKD structure f) (f focus) Source #

Instances
(Generic structure, ErrorUnless index structure ((0 <? index) && (index <=? Size (Rep structure))), GLens' (HasTotalPositionPSym index) (CRep f structure) (f focus), HasTotalPositionP index (CRep f structure) ~ Just (f focus), HasTotalPositionP index (CRep f (Indexed structure)) ~ Just (f' focus'), Coercible (HKD structure f) (CRep f structure Void), structure ~ Infer structure (f' focus') (f focus)) => HasPosition' index f structure focus Source # 
Instance details

Defined in Data.Generic.HKD.Position

Methods

position :: Lens' (HKD structure f) (f focus) Source #