HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulegeneric-optics-2.2.1.0Haskell2010

Data.Generics.Sum.Typed

Derive constructor-field-type-based prisms generically.

  • 1 class

Prisms

1 declaration
classclass AsType a s where
#

Sums that have a constructor with a field of the given type.

Methods

  • _Typed :: Prism' s a

    A 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 -> s

    Inject by type.

  • projectTyped :: s -> Maybe a

    Project by type.

Instances3AsType
  • Context a s => AsType a sDefined in generic-optics-2.2.1.0 · Data.Generics.Sum.Typed
  • AsType Void aDefined in generic-optics-2.2.1.0 · Data.Generics.Sum.Typed

    See Note [Uncluttering type signatures] >>> :t _Typed Int _Typed Int :: AsType Int s => Prism' s Int

  • AsType a VoidDefined in generic-optics-2.2.1.0 · Data.Generics.Sum.Typed

    See Note [Uncluttering type signatures] >>> :t _Typed _Typed :: AsType a s => Prism' s a