Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module is intended for internal use only, and may change without warning in subsequent releases.
Synopsis
- data PathTree e
- data Path
- type family GetFieldPaths s (name :: Symbol) g :: PathTree Symbol where ...
- type family GetNamePath (name :: Symbol) g (acc :: [Path]) :: Either Symbol [Path] where ...
- type family GetPositionPaths s (pos :: Nat) g :: PathTree (Nat, Nat) where ...
- type family GetPositionPath (pos :: Nat) g (k :: Nat) (acc :: [Path]) :: Either (Nat, Nat) [Path] where ...
- type family HideReps (g :: Type -> Type) (h :: Type -> Type) :: Constraint where ...
- type family AnyHasPath (path :: PathTree e) :: Bool where ...
- type family NoGenericError t where ...
Pathing
A map that allows reaching a specific field in a generic representation of a data type. Computed up front by generic optics for early error reporting and efficient data traversal.
Instances
r ~ b => GSetFieldProd ('[] :: [Path]) (M1 S m (Rec0 a)) (M1 S m (Rec0 b)) r Source # | |
Defined in Optics.Internal.Generic | |
GConstructorTuple g h a b => GConstructorSum ('[] :: [Path]) (M1 C m g) (M1 C m h) a b Source # | |
Defined in Optics.Internal.Generic | |
(r ~ a, s ~ b) => GFieldProd ('[] :: [Path]) (M1 S m (Rec0 a)) (M1 S m (Rec0 b)) r s Source # | |
GSetFieldProd path g1 h1 b => GSetFieldProd ('PathLeft ': path) (g1 :*: g2) (h1 :*: g2) b Source # | |
Defined in Optics.Internal.Generic gsetFieldProd :: (g1 :*: g2) x -> b -> (h1 :*: g2) x Source # | |
(GSetFieldProd path g1 h1 b, g2 ~ h2) => GSetFieldProd ('PathLeft ': path) (g1 :*: g2) (h1 :*: h2) b Source # | |
Defined in Optics.Internal.Generic gsetFieldProd :: (g1 :*: g2) x -> b -> (h1 :*: h2) x Source # | |
GSetFieldProd path g2 h2 b => GSetFieldProd ('PathRight ': path) (g1 :*: g2) (g1 :*: h2) b Source # | |
Defined in Optics.Internal.Generic gsetFieldProd :: (g1 :*: g2) x -> b -> (g1 :*: h2) x Source # | |
(GSetFieldProd path g2 h2 b, g1 ~ h1) => GSetFieldProd ('PathRight ': path) (g1 :*: g2) (h1 :*: h2) b Source # | |
Defined in Optics.Internal.Generic gsetFieldProd :: (g1 :*: g2) x -> b -> (h1 :*: h2) x Source # | |
GConstructorSum path g1 h1 a b => GConstructorSum ('PathLeft ': path) (g1 :+: g2) (h1 :+: g2) a b Source # | |
Defined in Optics.Internal.Generic | |
(GConstructorSum path g1 h1 a b, g2 ~ h2) => GConstructorSum ('PathLeft ': path) (g1 :+: g2) (h1 :+: h2) a b Source # | |
Defined in Optics.Internal.Generic | |
GConstructorSum path g2 h2 a b => GConstructorSum ('PathRight ': path) (g1 :+: g2) (g1 :+: h2) a b Source # | |
Defined in Optics.Internal.Generic | |
(GConstructorSum path g2 h2 a b, g1 ~ h1) => GConstructorSum ('PathRight ': path) (g1 :+: g2) (h1 :+: h2) a b Source # | |
Defined in Optics.Internal.Generic | |
GFieldProd path g1 h1 a b => GFieldProd ('PathLeft ': path) (g1 :*: g2) (h1 :*: g2) a b Source # | |
Defined in Optics.Internal.Generic | |
(GFieldProd path g1 h1 a b, g2 ~ h2) => GFieldProd ('PathLeft ': path) (g1 :*: g2) (h1 :*: h2) a b Source # | |
Defined in Optics.Internal.Generic | |
GFieldProd path g2 h2 a b => GFieldProd ('PathRight ': path) (g1 :*: g2) (g1 :*: h2) a b Source # | |
Defined in Optics.Internal.Generic | |
(GFieldProd path g2 h2 a b, g1 ~ h1) => GFieldProd ('PathRight ': path) (g1 :*: g2) (h1 :*: h2) a b Source # | |
Defined in Optics.Internal.Generic |
Names
type family GetFieldPaths s (name :: Symbol) g :: PathTree Symbol where ... Source #
Compute paths to a field with a specific name.
GetFieldPaths s name (M1 D _ g) = GetFieldPaths s name g | |
GetFieldPaths s name (g1 :+: g2) = 'PathTree (GetFieldPaths s name g1) (GetFieldPaths s name g2) | |
GetFieldPaths s name (M1 C _ g) = 'PathLeaf (GetNamePath name g '[]) | |
GetFieldPaths s name V1 = TypeError (('Text "Type " :<>: QuoteType s) :<>: 'Text " has no data constructors") |
type family GetNamePath (name :: Symbol) g (acc :: [Path]) :: Either Symbol [Path] where ... Source #
Compute path to a constructor in a sum or a field in a product with a specific name.
GetNamePath name (M1 D _ g) acc = GetNamePath name g acc | |
GetNamePath name (M1 C ('MetaCons name _ _) _) acc = 'Right (Reverse acc '[]) | |
GetNamePath name (g1 :+: g2) acc = FirstRight (GetNamePath name g1 ('PathLeft ': acc)) (GetNamePath name g2 ('PathRight ': acc)) | |
GetNamePath name (M1 S ('MetaSel ('Just name) _ _ _) _) acc = 'Right (Reverse acc '[]) | |
GetNamePath name (g1 :*: g2) acc = FirstRight (GetNamePath name g1 ('PathLeft ': acc)) (GetNamePath name g2 ('PathRight ': acc)) | |
GetNamePath name _ _ = 'Left name |
Positions
type family GetPositionPaths s (pos :: Nat) g :: PathTree (Nat, Nat) where ... Source #
Compute paths to a field at a specific position.
GetPositionPaths s pos (M1 D _ g) = GetPositionPaths s pos g | |
GetPositionPaths s pos (g1 :+: g2) = 'PathTree (GetPositionPaths s pos g1) (GetPositionPaths s pos g2) | |
GetPositionPaths s pos (M1 C _ g) = 'PathLeaf (GetPositionPath pos g 0 '[]) | |
GetPositionPaths s pos V1 = TypeError (('Text "Type " :<>: QuoteType s) :<>: 'Text " has no data constructors") |
type family GetPositionPath (pos :: Nat) g (k :: Nat) (acc :: [Path]) :: Either (Nat, Nat) [Path] where ... Source #
Compute path to a constructor in a sum or a field in a product at a specific position.
GetPositionPath pos (M1 D _ g) k acc = GetPositionPath pos g k acc | |
GetPositionPath pos (M1 C _ _) k acc = If (pos == (k + 1)) ('Right (Reverse acc '[])) ('Left '(pos, k + 1)) | |
GetPositionPath pos (g1 :+: g2) k acc = ContinueWhenLeft (GetPositionPath pos g1 k ('PathLeft ': acc)) g2 acc | |
GetPositionPath pos (M1 S _ _) k acc = If (pos == (k + 1)) ('Right (Reverse acc '[])) ('Left '(pos, k + 1)) | |
GetPositionPath pos (g1 :*: g2) k acc = ContinueWhenLeft (GetPositionPath pos g1 k ('PathLeft ': acc)) g2 acc | |
GetPositionPath pos _ k _ = 'Left '(pos, k) |
Misc
type family HideReps (g :: Type -> Type) (h :: Type -> Type) :: Constraint where ... Source #
Generate bogus equality constraints that attempt to unify generic representations with this type in case there is an error such as missing field, constructor etc. so these huge types don't leak into error messages.
HideReps g h = (g ~ Void1, h ~ Void1) |
type family AnyHasPath (path :: PathTree e) :: Bool where ... Source #
Check if any leaf in the tree has a '[Path]'.
AnyHasPath ('PathTree path1 path2) = AnyHasPath path1 || AnyHasPath path2 | |
AnyHasPath ('PathLeaf ('Right _)) = 'True | |
AnyHasPath ('PathLeaf ('Left _)) = 'False |
type family NoGenericError t where ... Source #