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