Copyright | (C) 2020 Csongor Kiss |
---|---|
License | BSD3 |
Maintainer | Csongor Kiss <kiss.csongor.kiss@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Derive positional product type getters and setters generically.
Synopsis
- type (<?) x y = Not (y <=? x)
- type family Size f :: Nat where ...
- type family CRep (a :: Type) :: G where ...
- class Context (i :: Nat) s t a b | s i -> a, t i -> b, s i b -> t, t i a -> s
- type Context_ i s t a b = (ErrorUnless i s ((0 <? i) && (i <=? Size (Rep s))), UnifyHead s t, UnifyHead t s)
- type Context' (i :: Nat) s a = (Generic s, ErrorUnless i s ((0 <? i) && (i <=? Size (Rep s))), Coercible (Rep s) (CRep s), GLens' (HasTotalPositionPSym i) (CRep s) a, Defined (Rep s) (NoGeneric s '[Text "arising from a generic lens focusing on the field at", ((((Text "position " :<>: QuoteType i) :<>: Text " of type ") :<>: QuoteType a) :<>: Text " in ") :<>: QuoteType s]) (() :: Constraint))
- type Context0 i s t a b = (Generic s, Generic t, GLens (HasTotalPositionPSym i) (CRep s) (CRep t) a b, Coercible (CRep s) (Rep s), Coercible (CRep t) (Rep t), Defined (Rep s) (NoGeneric s '[Text "arising from a generic lens focusing on the field at", ((((Text "position " :<>: QuoteType i) :<>: Text " of type ") :<>: QuoteType a) :<>: Text " in ") :<>: QuoteType s]) (() :: Constraint))
- derived0 :: forall i s t a b. Context0 i s t a b => Lens s t a b
- derived' :: forall i s a. Context' i s a => Lens s s a a
Documentation
type family CRep (a :: Type) :: G where ... Source #
In-order labeling of the generic tree with the field positions
We replace the (K1 R a) nodes with (K1 (Pos n) a), where n
is the position
of the field in question in the data type. This is convenient, because we
can reuse all the existing functions as long as they are polymorphic in the
first parameter of K1
.
class Context (i :: Nat) s t a b | s i -> a, t i -> b, s i b -> t, t i a -> s Source #
Instances
(ErrorUnless i s ((0 <? i) && (i <=? Size (Rep s))), HasTotalPositionP i (CRep s) ~ Just a, HasTotalPositionP i (CRep t) ~ Just b, HasTotalPositionP i (CRep (Indexed s)) ~ Just a', HasTotalPositionP i (CRep (Indexed t)) ~ Just b', t ~ Infer s a' b, s ~ Infer t b' a) => Context i (s :: Type) (t :: Type) (a :: Type) (b :: Type) Source # | |
Defined in Data.Generics.Product.Internal.Positions |
type Context_ i s t a b = (ErrorUnless i s ((0 <? i) && (i <=? Size (Rep s))), UnifyHead s t, UnifyHead t s) Source #
type Context' (i :: Nat) s a = (Generic s, ErrorUnless i s ((0 <? i) && (i <=? Size (Rep s))), Coercible (Rep s) (CRep s), GLens' (HasTotalPositionPSym i) (CRep s) a, Defined (Rep s) (NoGeneric s '[Text "arising from a generic lens focusing on the field at", ((((Text "position " :<>: QuoteType i) :<>: Text " of type ") :<>: QuoteType a) :<>: Text " in ") :<>: QuoteType s]) (() :: Constraint)) Source #
type Context0 i s t a b = (Generic s, Generic t, GLens (HasTotalPositionPSym i) (CRep s) (CRep t) a b, Coercible (CRep s) (Rep s), Coercible (CRep t) (Rep t), Defined (Rep s) (NoGeneric s '[Text "arising from a generic lens focusing on the field at", ((((Text "position " :<>: QuoteType i) :<>: Text " of type ") :<>: QuoteType a) :<>: Text " in ") :<>: QuoteType s]) (() :: Constraint)) Source #