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-lens-2.2.2.0Haskell2010

Data.Generics.Sum.Any

Derive a variety of prisms generically.

  • 1 class

Prisms

1 declaration

Running example:

Example6 expressions
:set -XTypeApplications:set -XDataKinds:set -XDeriveGenericimport GHC.Genericsimport Control.Lens:{data Animal  = Dog Dog  | Cat Name Age  | Duck Age  deriving (Generic, Show)data Dog  = MkDog  { name :: Name  , age  :: Age  }  deriving (Generic, Show)type Name = Stringtype Age  = Intdog, cat, duck :: Animaldog = Dog (MkDog "Shep" 3)cat = Cat "Mog" 5duck = Duck 2:}
classclass AsAny (sel :: k) a s | s sel -> a where
#

Sums that have generic prisms.

Methods

  • _As :: Prism s s a a

    A prism that projects a sum as identified by some selector. Currently supported selectors are constructor names and unique types. Compatible with the lens package's Control.Lens.Prism type.

    Example1 expression
    dog ^? _As @"Dog"Just (MkDog {name = "Shep", age = 3})
    Example1 expression
    dog ^? _As @DogJust (MkDog {name = "Shep", age = 3})
    Example1 expression
    dog ^? _As @"Cat"Nothing
    Example1 expression
    cat ^? _As @(Name, Age)Just ("Mog",5)
    Example1 expression
    cat ^? _As @"Cat"Just ("Mog",5)
    Example1 expression
    _As @"Cat" # ("Garfield", 6) :: AnimalCat "Garfield" 6
    Example1 expression
    duck ^? _As @AgeJust 2
Instances2AsAny
  • AsConstructor ctor s s a a => AsAny ctor a sDefined in generic-lens-2.2.2.0 · Data.Generics.Sum.Any
  • AsType a s => AsAny a a sDefined in generic-lens-2.2.2.0 · Data.Generics.Sum.Any