Types that can represent another type, either by being a sum with a constructor containing that type, or by actually being that type.
Methods
_Typed :: Prism' s aA prism that projects a constructor uniquely identifiable by the type of its field.
Example3 expressions dog ^? _Typed @DogJust (MkDog {name = "Shep", age = Age 3})cat ^? _Typed @(Name, Age)Just ("Mog",Age 5)dog ^? _Typed @Age......... The type Animal contains multiple constructors whose fields are of type Age.... The choice of constructor is thus ambiguous, could be any of:... Duck... Turtle...
injectTyped :: a -> sInject by type.
Example2 expressions :{dog :: Dogdog = MkDog "Fido" (Age 11)dogAsAnimal :: AnimaldogAsAnimal = injectTyped dogdogAsItself :: DogdogAsItself = injectTyped dog:}
projectTyped :: s -> Maybe aProject by type.
Example2 expressions :{dogAsAnimal :: AnimaldogAsAnimal = Dog (MkDog "Fido" (Age 11))mDog :: Maybe DogmDog = projectTyped dogAsAnimal:}
Instances4AsType
Context a s => AsType a sDefined in generic-optics-2.3.0.0 · Data.Generics.Sum.TypedAsType Void aDefined in generic-optics-2.3.0.0 · Data.Generics.Sum.TypedUncluttering type signatures (see Void)
Example1 expression :t _Typed @Int_Typed @Int :: AsType Int s => Prism' s Int
AsType a VoidDefined in generic-optics-2.3.0.0 · Data.Generics.Sum.TypedUncluttering type signatures (see Void)
Example1 expression :t _Typed_Typed :: AsType a s => Prism' s a
AsType a aDefined in generic-optics-2.3.0.0 · Data.Generics.Sum.TypedEvery type can be treated
asitself.