Precomposition with a pure function (right-to-left variant).
Moduleoptparse-applicative-0.19.0.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 verboseParser 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
- Packageoptparse-applicative-0.19.0.0
- Exports20
- LanguageHaskell98
- LicenceBSD-3-Clause
- SourceArrows.hs
Postcomposition with a pure function.
Postcomposition with a pure function (right-to-left variant).
Precomposition with a pure function.
Any instance of ArrowApply can be made into an instance of ArrowChoice by defining left = leftApp.
The identity arrow, which plays the role of return in arrow notation.
b
>───>Right-to-left composition. This is a synonym for (.), but it can be useful to make
the order of composition more apparent.
Left-to-right composition. This is useful if you want to write a morphism as a pipeline going from left to right.
The basic arrow class.
Instances should satisfy the following laws:
arr id = idarr (f >>> g) = arr f >>> arr gfirst (arr f) = arr (first f)first (f >>> g) = first f >>> first gfirst f >>> arrfst= arrfst>>> ffirst f >>> arr (id *** g) = arr (id *** g) >>> first ffirst (first f) >>> arr assoc = arr assoc >>> first f
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 cLift a function to an arrow.
b ╭───╮ c >───┤ f ├───> ╰───╯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.
The default definition may be overridden with a more efficient version if desired.
b ╭─────╮ c >───┼─ f ─┼───> >───┼─────┼───> d ╰─────╯ dsecond :: a b c -> a (d, b) (d, c)Send the second component of the input through the argument arrow, and copy the rest unchanged to the output.
The default definition may be overridden with a more efficient version if desired.
d ╭─────╮ d >───┼─────┼───> >───┼─ f ─┼───> b ╰─────╯ c(***) :: a b c -> a b' c' -> a (b, b') (c, c')infixr 3Split 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.
b ╭─────╮ c >───┼─ f ─┼───> >───┼─ g ─┼───> b'╰─────╯ c'(&&&) :: a b c -> a b c' -> a b (c, c')infixr 3Fanout: send the input to both argument arrows and combine their output.
The default definition may be overridden with a more efficient version if desired.
╭───────╮ c b │ ┌─ f ─┼───> >───┼─┤ │ │ └─ g ─┼───> ╰───────╯ c'
Some arrows allow application of arrow inputs to other inputs. Instances should satisfy the following laws:
first (arr (\x -> arr (\y -> (x,y)))) >>> app = idfirst (arr (g >>>)) >>> app = second g >>> appfirst (arr (>>> h)) >>> app = app >>> h
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-10.0.0 · GHC.Internal.Control.ArrowArrowApply (->)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
Choice, for arrows that support it. This class underlies the
if and case constructs in arrow notation.
Instances should satisfy the following laws:
left (arr f) = arr (left f)left (f >>> g) = left f >>> left gf >>> arr Left = arr Left >>> left fleft f >>> arr (id +++ g) = arr (id +++ g) >>> left fleft (left f) >>> arr assocsum = arr assocsum >>> left f
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 2Split 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 2Fanin: 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-10.0.0 · GHC.Internal.Control.ArrowArrowChoice (->)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
The ArrowApply class is equivalent to Monad: any monad gives rise to a Kleisli arrow, and any instance of ArrowApply defines a monad.
Constructors
ArrowMonad (a () b)
Instances5Monad, Functor, Applicative, Alternative, MonadPlus
ArrowApply a => Monad (ArrowMonad a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowArrow a => Functor (ArrowMonad a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowArrow a => Applicative (ArrowMonad a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowArrowPlus a => Alternative (ArrowMonad a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
A monoid on arrows.
Methods
zeroArrow :: a b c
Kleisli arrows of a monad.
Constructors
KleislirunKleisli :: a -> m b
Instances16Category, Generic1, Arrow, ArrowApply, ArrowChoice, ArrowPlus, …
Monad m => Category (Kleisli m)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowGeneric1 (Kleisli m a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowMonad m => Arrow (Kleisli m)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowMonad m => ArrowApply (Kleisli m)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowMonad m => ArrowChoice (Kleisli m)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowMonadPlus m => ArrowPlus (Kleisli m)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowMonadPlus m => ArrowZero (Kleisli m)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowMonadFix m => ArrowLoop (Kleisli m)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Monad.FixBeware 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.Monad m => Monad (Kleisli m a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowFunctor m => Functor (Kleisli m a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowApplicative m => Applicative (Kleisli m a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowAlternative m => Alternative (Kleisli m a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowMonadPlus m => MonadPlus (Kleisli m a)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.ArrowGeneric (Kleisli m a b)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrowtype Rep (Kleisli m a b) = D1 ('MetaDataDefined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow"Kleisli"
"GHC.Internal.Control.Arrow"
"ghc-internal"
'True) (C1 ('MetaCons"Kleisli"
'PrefixI 'True) (S1 ('MetaSel ('Just"runKleisli"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (a -> m b))))type Rep1 (Kleisli m a) = D1 ('MetaDataDefined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow"Kleisli"
"GHC.Internal.Control.Arrow"
"ghc-internal"
'True) (C1 ('MetaCons"Kleisli"
'PrefixI 'True) (S1 ('MetaSel ('Just"runKleisli"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (FUN 'Many a :.: Rec1 m)))
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
- left tightening
- right tightening
- sliding
- vanishing
- 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╭──────────────╮ b │ ╭───╮ │ c >───┼─────┤ ├────┼───> │ ┌─┤ ├─┐ │ │ d │ ╰───╯ │ │ │ └───<───┘ │ ╰──────────────╯
Instances2ArrowLoop
MonadFix m => ArrowLoop (Kleisli m)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Monad.FixBeware 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-10.0.0 · GHC.Internal.Control.Monad.Fix
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.
Instances2Category, Arrow
Applicative f => Category (A f)Defined in optparse-applicative-0.19.0.0 · Options.Applicative.ArrowsApplicative f => Arrow (A f)Defined in optparse-applicative-0.19.0.0 · Options.Applicative.Arrows
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.
Convert an arrow back to an applicative value.
This function can be used to return a result of type Parser from an arrow command.
The type of arrows associated to the applicative Parser functor.