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

Moduleoptparse-applicative-0.18.1.0Haskell98

Options.Applicative.Arrows

This module contains an arrow interface for option parsers, which allows to define and combine parsers using the arrow notation and arrow combinators.

The arrow syntax is particularly useful to create parsers of nested structures, or records where the order of fields is different from the order in which the parsers should be applied.

For example, an Options.Applicative.Builder.arguments parser often needs to be applied last, and that makes it inconvenient to use it for a field which is not the last one in a record.

Using the arrow syntax and the functions in this module, one can write, e.g.:

data Options = Options
  { optArgs :: [String]
  , optVerbose :: Bool }

opts :: Parser Options
opts = runA $ proc () -> do
  verbose <- asA (switch (short 'v')) -< ()
  args <- asA (arguments str idm) -< ()
  returnA -< Options args verbose

Parser arrows, created out of regular Parser values using the asA function, are arrows taking () as argument and returning the parsed value.

  • 4 types
  • 6 classes
  • 10 values
classclass Category a => Arrow (a :: Type -> Type -> Type) where
#

The basic arrow class.

Instances should satisfy the following laws:

where

assoc ((a,b),c) = (a,(b,c))

The other combinators have sensible default definitions, which may be overridden for efficiency.

Methods

  • arr :: (b -> c) -> a b c

    Lift a function to an arrow.

  • first :: a b c -> a (b, d) (c, d)

    Send the first component of the input through the argument arrow, and copy the rest unchanged to the output.

  • second :: a b c -> a (d, b) (d, c)

    A mirror image of first.

    The default definition may be overridden with a more efficient version if desired.

  • (***) :: a b c -> a b' c' -> a (b, b') (c, c')infixr 3

    Split the input between the two argument arrows and combine their output. Note that this is in general not a functor.

    The default definition may be overridden with a more efficient version if desired.

  • (&&&) :: a b c -> a b c' -> a b (c, c')infixr 3

    Fanout: send the input to both argument arrows and combine their output.

    The default definition may be overridden with a more efficient version if desired.

Instances3Arrow
  • Applicative f => Arrow (A f)Defined in optparse-applicative-0.18.1.0 · Options.Applicative.Arrows
  • Monad m => Arrow (Kleisli m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
  • Arrow (->)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
classclass Arrow a => ArrowLoop (a :: Type -> Type -> Type) where
#

The loop operator expresses computations in which an output value is fed back as input, although the computation occurs only once. It underlies the rec value recursion construct in arrow notation. loop should satisfy the following laws:

extension

loop (arr f) = arr (\ b -> fst (fix (\ (c,d) -> f (b,d))))

left tightening

loop (first h >>> f) = h >>> loop f

right tightening

loop (f >>> first h) = loop f >>> h

sliding

loop (f >>> arr (id *** k)) = loop (arr (id *** k) >>> f)

vanishing

loop (loop f) = loop (arr unassoc >>> f >>> arr assoc)

superposing

second (loop f) = loop (arr assoc >>> second f >>> arr unassoc)

where

assoc ((a,b),c) = (a,(b,c))
unassoc (a,(b,c)) = ((a,b),c)

Methods

  • loop :: a (b, d) (c, d) -> a b c
Instances2ArrowLoop
  • MonadFix m => ArrowLoop (Kleisli m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow

    Beware that for many monads (those for which the >>= operation is strict) this instance will not satisfy the right-tightening law required by the ArrowLoop class.

  • ArrowLoop (->)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
classclass Arrow a => ArrowChoice (a :: Type -> Type -> Type) where
#

Choice, for arrows that support it. This class underlies the if and case constructs in arrow notation.

Instances should satisfy the following laws:

where

assocsum (Left (Left x)) = Left x
assocsum (Left (Right y)) = Right (Left y)
assocsum (Right z) = Right (Right z)

The other combinators have sensible default definitions, which may be overridden for efficiency.

Methods

  • left :: a b c -> a (Either b d) (Either c d)

    Feed marked inputs through the argument arrow, passing the rest through unchanged to the output.

  • right :: a b c -> a (Either d b) (Either d c)

    A mirror image of left.

    The default definition may be overridden with a more efficient version if desired.

  • (+++) :: a b c -> a b' c' -> a (Either b b') (Either c c')infixr 2

    Split the input between the two argument arrows, retagging and merging their outputs. Note that this is in general not a functor.

    The default definition may be overridden with a more efficient version if desired.

  • (|||) :: a b d -> a c d -> a (Either b c) dinfixr 2

    Fanin: Split the input between the two argument arrows and merge their outputs.

    The default definition may be overridden with a more efficient version if desired.

Instances2ArrowChoice
  • Monad m => ArrowChoice (Kleisli m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
  • ArrowChoice (->)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
classclass Arrow a => ArrowApply (a :: Type -> Type -> Type) where
#

Some arrows allow application of arrow inputs to other inputs. Instances should satisfy the following laws:

Such arrows are equivalent to monads (see ArrowMonad).

Methods

  • app :: a (a b c, b) c
Instances2ArrowApply
  • Monad m => ArrowApply (Kleisli m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
  • ArrowApply (->)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow
value(<<^) :: Arrow a => a c d -> (b -> c) -> a b d
#

Precomposition with a pure function (right-to-left variant).

value(>>^) :: Arrow a => a b c -> (c -> d) -> a b d
#

Postcomposition with a pure function.

value(^<<) :: Arrow a => (c -> d) -> a b c -> a b d
#

Postcomposition with a pure function (right-to-left variant).

value(^>>) :: Arrow a => (b -> c) -> a c d -> a b d
#

Precomposition with a pure function.

valuereturnA :: Arrow a => a b b
#

The identity arrow, which plays the role of return in arrow notation.

value(<<<) :: Category cat => cat b c -> cat a b -> cat a c
#

Right-to-left composition

value(>>>) :: Category cat => cat a b -> cat b c -> cat a c
#

Left-to-right composition

newtypenewtype ArrowMonad (a :: Type -> Type -> Type) b
#

The ArrowApply class is equivalent to Monad: any monad gives rise to a Kleisli arrow, and any instance of ArrowApply defines a monad.

Constructors

Instances5Monad, Functor, Applicative, Alternative, MonadPlus
newtypenewtype Kleisli (m :: Type -> Type) a b
#

Kleisli arrows of a monad.

Constructors

Instances16Category, Generic1, Arrow, ArrowApply, ArrowChoice, ArrowLoop, …
newtypenewtype A (f :: Type -> Type) a b
#

For any Applicative functor f, A f is the Arrow instance associated to f.

The A constructor can be used to convert a value of type f (a -> b) into an arrow.

Constructors

Instances2Category, Arrow
  • Applicative f => Category (A f)Defined in optparse-applicative-0.18.1.0 · Options.Applicative.Arrows
  • Applicative f => Arrow (A f)Defined in optparse-applicative-0.18.1.0 · Options.Applicative.Arrows
valueasA :: Applicative f => f a -> A f () a
#

Convert a value of type f a into an arrow taking () as argument.

Applied to a value of type Parser, it turns it into an arrow that can be used inside an arrow command, or passed to arrow combinators.

valuerunA :: Applicative f => A f () a -> f a
#

Convert an arrow back to an applicative value.

This function can be used to return a result of type Parser from an arrow command.