optics-core-0.4.1.1: Optics as an abstract interface: core definitions

Safe Haskell | None
Language | Haskell2010

Optics.Internal.Generic.TypeLevel

Contents

- Pathing
  - Names
  - Positions
- Misc

Description

This module is intended for internal use only, and may change without warning in subsequent releases.

Synopsis

- data PathTree e
  - = PathTree (PathTree e) (PathTree e)
  - | PathLeaf (Either e [Path])
- data Path
  - = PathLeft
  - | PathRight
- type family GetFieldPaths (s :: t) (name :: Symbol) (g :: k -> Type) :: PathTree Symbol where ...
- type family GetNamePath (name :: Symbol) (g :: k -> Type) (acc :: [Path]) :: Either Symbol [Path] where ...
- type family GetPositionPaths (s :: t) (pos :: Nat) (g :: k -> Type) :: PathTree (Nat, Nat) where ...
- type family GetPositionPath (pos :: Nat) (g :: k -> Type) (k1 :: Nat) (acc :: [Path]) :: Either (Nat, Nat) [Path] where ...
- type family HideReps (g :: Type -> Type) (h :: Type -> Type) where ...
- type family AnyHasPath (path :: PathTree e) :: Bool where ...
- type family NoGenericError (t1 :: t) :: k where ...

# Pathing

data PathTree e Source #

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.

Constructors

PathTree (PathTree e) (PathTree e) |
PathLeaf (Either e [Path]) |

data Path Source #

Constructors

PathLeft |
PathRight |

#### Instances

Instances details

r ~ b => GSetFieldProd ('[] :: [Path]) (M1 S m (Rec0 a)) (M1 S m (Rec0 b)) r Source # |
Instance details Defined in Optics.Internal.Generic Methods gsetFieldProd :: M1 S m (Rec0 a) x -> r -> M1 S m (Rec0 b) x Source #
GConstructorTuple g h a b => GConstructorSum ('[] :: [Path]) (M1 C m g) (M1 C m h) a b Source # |
Instance details Defined in Optics.Internal.Generic Methods gconstructorSum :: Prism (M1 C m g x) (M1 C m h x) a b Source #
(r ~ a, s ~ b) => GFieldProd ('[] :: [Path]) (M1 S m (Rec0 a)) (M1 S m (Rec0 b)) r s Source # |
Instance details Defined in Optics.Internal.Generic Methods gfieldProd :: LensVL (M1 S m (Rec0 a) x) (M1 S m (Rec0 b) x) r s Source #
GSetFieldProd path g1 h1 b => GSetFieldProd ('PathLeft ': path) (g1 :*: g2) (h1 :*: g2) b Source # |
Instance details Defined in Optics.Internal.Generic Methods 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 # |
Instance details Defined in Optics.Internal.Generic Methods gsetFieldProd :: (g1 :*: g2) x -> b -> (h1 :*: h2) x Source #
GSetFieldProd path g2 h2 b => GSetFieldProd ('PathRight ': path) (g1 :*: g2) (g1 :*: h2) b Source # |
Instance details Defined in Optics.Internal.Generic Methods 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 # |
Instance details Defined in Optics.Internal.Generic Methods 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 # |
Instance details Defined in Optics.Internal.Generic Methods gconstructorSum :: Prism ((g1 :+: g2) x) ((h1 :+: g2) x) a b Source #
(GConstructorSum path g1 h1 a b, g2 ~ h2) => GConstructorSum ('PathLeft ': path) (g1 :+: g2) (h1 :+: h2) a b Source # |
Instance details Defined in Optics.Internal.Generic Methods gconstructorSum :: Prism ((g1 :+: g2) x) ((h1 :+: h2) x) a b Source #
GConstructorSum path g2 h2 a b => GConstructorSum ('PathRight ': path) (g1 :+: g2) (g1 :+: h2) a b Source # |
Instance details Defined in Optics.Internal.Generic Methods gconstructorSum :: Prism ((g1 :+: g2) x) ((g1 :+: h2) x) a b Source #
(GConstructorSum path g2 h2 a b, g1 ~ h1) => GConstructorSum ('PathRight ': path) (g1 :+: g2) (h1 :+: h2) a b Source # |
Instance details Defined in Optics.Internal.Generic Methods gconstructorSum :: Prism ((g1 :+: g2) x) ((h1 :+: h2) x) a b Source #
GFieldProd path g1 h1 a b => GFieldProd ('PathLeft ': path) (g1 :*: g2) (h1 :*: g2) a b Source # |
Instance details Defined in Optics.Internal.Generic Methods gfieldProd :: LensVL ((g1 :*: g2) x) ((h1 :*: g2) x) a b Source #
(GFieldProd path g1 h1 a b, g2 ~ h2) => GFieldProd ('PathLeft ': path) (g1 :*: g2) (h1 :*: h2) a b Source # |
Instance details Defined in Optics.Internal.Generic Methods gfieldProd :: LensVL ((g1 :*: g2) x) ((h1 :*: h2) x) a b Source #
GFieldProd path g2 h2 a b => GFieldProd ('PathRight ': path) (g1 :*: g2) (g1 :*: h2) a b Source # |
Instance details Defined in Optics.Internal.Generic Methods gfieldProd :: LensVL ((g1 :*: g2) x) ((g1 :*: h2) x) a b Source #
(GFieldProd path g2 h2 a b, g1 ~ h1) => GFieldProd ('PathRight ': path) (g1 :*: g2) (h1 :*: h2) a b Source # |
Instance details Defined in Optics.Internal.Generic Methods gfieldProd :: LensVL ((g1 :*: g2) x) ((h1 :*: h2) x) a b Source #

## Names

type family GetFieldPaths (s :: t) (name :: Symbol) (g :: k -> Type) :: PathTree Symbol where ... Source #

Compute paths to a field with a specific name.

Equations

GetFieldPaths (s :: t) name (M1 D _1 g :: k -> Type) = GetFieldPaths s name g |
GetFieldPaths (s :: t) name (g1 :+: g2 :: k -> Type) = 'PathTree (GetFieldPaths s name g1) (GetFieldPaths s name g2) |
GetFieldPaths (s :: t) name (M1 C _1 g :: k -> Type) = 'PathLeaf (GetNamePath name g ('[] :: [Path])) |
GetFieldPaths (s :: t) name (V1 :: k -> Type) = TypeError (('Text "Type " ':<>: QuoteType s) ':<>: 'Text " has no data constructors") :: PathTree Symbol |

type family GetNamePath (name :: Symbol) (g :: k -> Type) (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.

Equations

GetNamePath name (M1 D _1 g :: k -> Type) acc = GetNamePath name g acc |
GetNamePath name (M1 C ('MetaCons name _1 _2) _3 :: k -> Type) acc = 'Right (Reverse acc ('[] :: [Path])) :: Either Symbol [Path] |
GetNamePath name (g1 :+: g2 :: k -> Type) acc = FirstRight (GetNamePath name g1 ('PathLeft ': acc)) (GetNamePath name g2 ('PathRight ': acc)) |
GetNamePath name (M1 S ('MetaSel ('Just name) _1 _2 _3) _4 :: k -> Type) acc = 'Right (Reverse acc ('[] :: [Path])) :: Either Symbol [Path] |
GetNamePath name (g1 :*: g2 :: k -> Type) acc = FirstRight (GetNamePath name g1 ('PathLeft ': acc)) (GetNamePath name g2 ('PathRight ': acc)) |
GetNamePath name (_1 :: k -> Type) _2 = 'Left name :: Either Symbol [Path] |

## Positions

type family GetPositionPaths (s :: t) (pos :: Nat) (g :: k -> Type) :: PathTree (Nat, Nat) where ... Source #

Compute paths to a field at a specific position.

Equations

GetPositionPaths (s :: t) pos (M1 D _1 g :: k -> Type) = GetPositionPaths s pos g |
GetPositionPaths (s :: t) pos (g1 :+: g2 :: k -> Type) = 'PathTree (GetPositionPaths s pos g1) (GetPositionPaths s pos g2) |
GetPositionPaths (s :: t) pos (M1 C _1 g :: k -> Type) = 'PathLeaf (GetPositionPath pos g 0 ('[] :: [Path])) |
GetPositionPaths (s :: t) pos (V1 :: k -> Type) = TypeError (('Text "Type " ':<>: QuoteType s) ':<>: 'Text " has no data constructors") :: PathTree (Nat, Nat) |

type family GetPositionPath (pos :: Nat) (g :: k -> Type) (k1 :: 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.

Equations

GetPositionPath pos (M1 D _1 g :: k1 -> Type) k2 acc = GetPositionPath pos g k2 acc |
GetPositionPath pos (M1 C _1 _2 :: k1 -> Type) k2 acc = If (pos == (k2 + 1)) ('Right (Reverse acc ('[] :: [Path])) :: Either (Nat, Natural) [Path]) ('Left '(pos, k2 + 1) :: Either (Nat, Natural) [Path]) |
GetPositionPath pos (g1 :+: g2 :: k1 -> Type) k2 acc = ContinueWhenLeft (GetPositionPath pos g1 k2 ('PathLeft ': acc)) g2 acc |
GetPositionPath pos (M1 S _1 _2 :: k1 -> Type) k2 acc = If (pos == (k2 + 1)) ('Right (Reverse acc ('[] :: [Path])) :: Either (Nat, Natural) [Path]) ('Left '(pos, k2 + 1) :: Either (Nat, Natural) [Path]) |
GetPositionPath pos (g1 :*: g2 :: k1 -> Type) k2 acc = ContinueWhenLeft (GetPositionPath pos g1 k2 ('PathLeft ': acc)) g2 acc |
GetPositionPath pos (_1 :: k1 -> Type) k2 _2 = 'Left '(pos, k2) :: Either (Nat, Nat) [Path] |

# Misc

type family HideReps (g :: Type -> Type) (h :: Type -> Type) 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.

Equations

HideReps g h = (g ~ (Void1 :: Type -> Type), h ~ (Void1 :: Type -> Type)) |

type family AnyHasPath (path :: PathTree e) :: Bool where ... Source #

Check if any leaf in the tree has a '[Path]'.

Equations

AnyHasPath ('PathTree path1 path2 :: PathTree e) = AnyHasPath path1 || AnyHasPath path2 |
AnyHasPath ('PathLeaf ('Right _1 :: Either e [Path]) :: PathTree e) = 'True |
AnyHasPath ('PathLeaf ('Left _1 :: Either e [Path]) :: PathTree e) = 'False |

type family NoGenericError (t1 :: t) :: k where ... Source #

Equations

NoGenericError (t2 :: t1) = TypeError (('Text "Type " ':<>: QuoteType t2) ':<>: 'Text " doesn't have a Generic instance") :: k |