HORIZON HASKELLDocslts/ghc-9.14.x45dd5372026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 45dd537 · 2026-10-11

Moduleeither-n-0.1.0.0Haskell2010

Data.Lens.Injection.Injection1

The first injection of a sum type, as a prism. The sum-type dual of Control.Lens.Field1.

  • 1 class
  • Packageeither-n-0.1.0.0
  • Exports1
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceInjection1.hs
classclass Injection1 s t a b | s -> a, t -> b, s b -> t, t a -> s where
#

Access the first constructor of a sum type.

Where Control.Lens._1 is the first projection out of a product, _I1 is the first injection into a sum.

The default implementation is the prism to the first constructor of a Generic type, injection (Proxy :: Proxy 0).

Example3 expressions
data T = C1 Int | C2 deriving (Show, Generic)instance Injection1 T T Int IntC1 1 ^? _I1Just 1
Example1 expression
C2 ^? _I1Nothing
Example1 expression
_I1 # 1 :: TC1 1

Methods

Instances11Injection1, …
  • Injection1 Bool Bool () ()Defined in either-n-0.1.0.0 · Data.Lens.Injection.Injection1
    Example1 expression
    False ^? _I1Just ()
    Example1 expression
    True ^? _I1Nothing
    Example1 expression
    _I1 # () :: BoolFalse
  • Injection1 Ordering Ordering () ()Defined in either-n-0.1.0.0 · Data.Lens.Injection.Injection1
    Example1 expression
    LT ^? _I1Just ()
    Example1 expression
    EQ ^? _I1Nothing
    Example1 expression
    GT ^? _I1Nothing
    Example1 expression
    _I1 # () :: OrderingLT
  • Injection1 () () () ()Defined in either-n-0.1.0.0 · Data.Lens.Injection.Injection1

    A sum of one nullary constructor, so _I1 always matches.

    Example1 expression
    () ^? _I1Just ()
    Example1 expression
    _I1 # () :: ()()
  • Injection1 (Identity a) (Identity b) a bDefined in either-n-0.1.0.0 · Data.Lens.Injection.Injection1

    A sum of one constructor, so _I1 always matches.

    Example1 expression
    Identity 1 ^? _I1Just 1
    Example1 expression
    _I1 # 1 :: Identity IntIdentity 1
    Example1 expression
    over _I1 show (Identity 1)Identity "1"
  • Injection1 (Maybe a) (Maybe a) () ()Defined in either-n-0.1.0.0 · Data.Lens.Injection.Injection1
    Example1 expression
    (Nothing :: Maybe Int) ^? _I1Just ()
    Example1 expression
    Just 1 ^? _I1Nothing
    Example1 expression
    _I1 # () :: Maybe IntNothing
  • Injection1 [a] [a] () ()Defined in either-n-0.1.0.0 · Data.Lens.Injection.Injection1

    A list is the sum of the empty list and a cons cell.

    Example1 expression
    ([] :: [Int]) ^? _I1Just ()
    Example1 expression
    [1, 2, 3] ^? _I1Nothing
    Example1 expression
    _I1 # () :: [Int][]
  • Injection1 (Either a c) (Either b c) a bDefined in either-n-0.1.0.0 · Data.Lens.Injection.Injection1
    Example1 expression
    (Left 1 :: Either Int String) ^? _I1Just 1
    Example1 expression
    (Right "x" :: Either Int String) ^? _I1Nothing
    Example1 expression
    _I1 # 1 :: Either Int StringLeft 1
    Example1 expression
    over _I1 show (Left 1 :: Either Int Bool)Left "1"
  • Injection1 (Either3 a b c) (Either3 a' b c) a a'Defined in either-n-0.1.0.0 · Data.Either3.Either3
    Example1 expression
    (First3 1 :: Either3 Int Bool String) ^? _I1Just 1
    Example1 expression
    over _I1 show (First3 1 :: Either3 Int Bool String)First3 "1"
  • Injection1 (Either3T Identity a b c) (Either3T Identity a' b c) a a'Defined in either-n-0.1.0.0 · Data.Either3.Either3T
    Example1 expression
    e3 (First3 "x") ^? _I1Just "x"
  • Injection1 (Sum f g a) (Sum f' g a) (f a) (f' a)Defined in either-n-0.1.0.0 · Data.Lens.Injection.Injection1
    Example1 expression
    (InL (Just 1) :: Sum Maybe [] Int) ^? _I1Just (Just 1)
    Example1 expression
    (InR [1] :: Sum Maybe [] Int) ^? _I1Nothing
    Example1 expression
    _I1 # Just 1 :: Sum Maybe [] IntInL (Just 1)
  • Injection1 ((:+:) f g p) ((:+:) f' g p) (f p) (f' p)Defined in either-n-0.1.0.0 · Data.Lens.Injection.Injection1
    Example1 expression
    (L1 (Just 1) :: (Maybe :+: []) Int) ^? _I1Just (Just 1)
    Example1 expression
    (R1 [1] :: (Maybe :+: []) Int) ^? _I1Nothing
    Example1 expression
    _I1 # Just 1 :: (Maybe :+: []) IntL1 (Just 1)