Structural subtyping between sums. A sum Sub is a subtype of another sum
Sup if a value of Sub can be given (modulo naming of constructors)
whenever a value of Sup is expected. In the running example for instance,
FourLeggedAnimal is a subtype of Animal since a value of the former can
be given as a value of the latter (renaming Dog4 to Dog and Cat4 to
Cat).
Methods
_Sub :: Prism' sup subA prism that captures structural subtyping. Allows a substructure to be injected (upcast) into a superstructure or a superstructure to be downcast into a substructure (which may fail).
Example1 expression _Sub # dog4 :: AnimalDog (MkDog {name = "Snowy", age = 4})
Example1 expression cat ^? _Sub :: Maybe FourLeggedAnimalJust (Cat4 "Mog" 5)
Example1 expression duck ^? _Sub :: Maybe FourLeggedAnimalNothing
injectSub :: sub -> supInjects a subtype into a supertype (upcast).
projectSub :: sup -> Maybe subProjects a subtype from a supertype (downcast).
Instances4AsSubtype
AsSubtype Void aDefined in generic-lens-2.2.2.0 · Data.Generics.Sum.SubtypeUncluttering type signatures (see Void)
Example1 expression :t +d _Sub @Int_Sub @Int :: (AsSubtype Int sup, Choice p, Applicative f) => p Int (f Int) -> p sup (f sup)
AsSubtype a VoidDefined in generic-lens-2.2.2.0 · Data.Generics.Sum.SubtypeUncluttering type signatures (see Void)
Example1 expression :t +d _Sub_Sub :: (AsSubtype sub sup, Choice p, Applicative f) => p sub (f sub) -> p sup (f sup)
AsSubtype a aDefined in generic-lens-2.2.2.0 · Data.Generics.Sum.SubtypeReflexive case
Example1 expression _Sub # dog :: AnimalDog (MkDog {name = "Shep", age = 3})
Context sub sup => AsSubtype sub supDefined in generic-lens-2.2.2.0 · Data.Generics.Sum.Subtype