optparse-applicative-0.18.1.0: Utilities and combinators for parsing command line options

Safe Haskell | Safe-Inferred
Language | Haskell98

Options.Applicative.Arrows

Description

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 `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.

Synopsis

- module Control.Arrow
- newtype A (f :: Type -> Type) a b = A {
  - unA :: f (a -> b)
  }
- asA :: Applicative f => f a -> A f () a
- runA :: Applicative f => A f () a -> f a
- type ParserA = A Parser

# Documentation

module Control.Arrow

newtype 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

A |
Fields unA :: f (a -> b)

#### Instances

Instances details

Applicative f => Category (A f :: Type -> Type -> Type) # |
Instance details Defined in Options.Applicative.Arrows Methods id :: A f a a # (.) :: A f b c -> A f a b -> A f a c #
Applicative f => Arrow (A f) # |
Instance details Defined in Options.Applicative.Arrows Methods arr :: (b -> c) -> A f b c # first :: A f b c -> A f (b, d) (c, d) # second :: A f b c -> A f (d, b) (d, c) # (***) :: A f b c -> A f b' c' -> A f (b, b') (c, c') # (&&&) :: A f b c -> A f b c' -> A f b (c, c') #

asA :: 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.

runA :: 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.

type ParserA = A Parser #

The type of arrows associated to the applicative `Parser` functor.