optics-core-0.4: Optics as an abstract interface: core definitions
Safe HaskellSafe-Inferred
LanguageHaskell2010

Optics.Internal.Generic.TypeLevel

Description

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

Synopsis

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, 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 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 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 #

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 #

(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 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 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 #

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 #

(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 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 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 #

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 #

Names

type family GetFieldPaths s (name :: Symbol) g :: PathTree Symbol where ... Source #

Compute paths to a field with a specific name.

Equations

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.

Equations

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.

Equations

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.

Equations

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.

Equations

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]'.

Equations

AnyHasPath ('PathTree path1 path2) = AnyHasPath path1 || AnyHasPath path2 
AnyHasPath ('PathLeaf ('Right _)) = 'True 
AnyHasPath ('PathLeaf ('Left _)) = 'False 

type family NoGenericError t where ... Source #

Equations

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