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
Context sub sup => AsSubtype sub supDefined in generic-optics-2.2.1.0 · Data.Generics.Sum.SubtypeAsSubtype Void aDefined in generic-optics-2.2.1.0 · Data.Generics.Sum.SubtypeSee Note [Uncluttering type signatures] >>> :t _Sub
Int _SubInt :: AsSubtype Int sup => Prism' sup IntAsSubtype a VoidDefined in generic-optics-2.2.1.0 · Data.Generics.Sum.SubtypeSee Note [Uncluttering type signatures] _Sub :: (AsSubtype sub sup, Data.Profunctor.Choice.Choice p, Applicative f) => p sub (f sub) -> p sup (f sup)
AsSubtype a aDefined in generic-optics-2.2.1.0 · Data.Generics.Sum.SubtypeReflexive case >>> _Sub # dog :: Animal Dog (MkDog {name =
Shep, age = 3})