optparse-applicative-0.18.1.0: Utilities and combinators for parsing command line options
Safe HaskellSafe-Inferred
LanguageHaskell98

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
  • class Category a => Arrow (a :: Type -> Type -> Type) where
    • arr :: (b -> c) -> a b c
    • first :: a b c -> a (b, d) (c, d)
    • second :: a b c -> a (d, b) (d, c)
    • (***) :: a b c -> a b' c' -> a (b, b') (c, c')
    • (&&&) :: a b c -> a b c' -> a b (c, c')
  • class ArrowZero a => ArrowPlus (a :: Type -> Type -> Type) where
    • (<+>) :: a b c -> a b c -> a b c
  • class Arrow a => ArrowLoop (a :: Type -> Type -> Type) where
    • loop :: a (b, d) (c, d) -> a b c
  • class Arrow a => ArrowZero (a :: Type -> Type -> Type) where
  • (>>>) :: forall {k} cat (a :: k) (b :: k) (c :: k). Category cat => cat a b -> cat b c -> cat a c
  • class Arrow a => ArrowChoice (a :: Type -> Type -> Type) where
    • left :: a b c -> a (Either b d) (Either c d)
    • right :: a b c -> a (Either d b) (Either d c)
    • (+++) :: a b c -> a b' c' -> a (Either b b') (Either c c')
    • (|||) :: a b d -> a c d -> a (Either b c) d
  • class Arrow a => ArrowApply (a :: Type -> Type -> Type) where
    • app :: a (a b c, b) c
  • (<<<) :: forall {k} cat (b :: k) (c :: k) (a :: k). Category cat => cat b c -> cat a b -> cat a c
  • (<<^) :: Arrow a => a c d -> (b -> c) -> a b d
  • (>>^) :: Arrow a => a b c -> (c -> d) -> a b d
  • (^<<) :: Arrow a => (c -> d) -> a b c -> a b d
  • (^>>) :: Arrow a => (b -> c) -> a c d -> a b d
  • newtype Kleisli (m :: Type -> Type) a b = Kleisli {}
  • newtype ArrowMonad (a :: Type -> Type -> Type) b = ArrowMonad (a () b)
  • leftApp :: ArrowApply a => a b c -> a (Either b d) (Either c d)
  • returnA :: Arrow a => a b b
  • 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

class Category a => Arrow (a :: Type -> Type -> Type) where #

Minimal complete definition

arr, (first | (***))

Methods

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

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

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

(***) :: a b c -> a b' c' -> a (b, b') (c, c') #

(&&&) :: a b c -> a b c' -> a b (c, c') #

Instances

Instances details
Monad m => Arrow (Kleisli m) 
Instance details

Defined in Control.Arrow

Methods

arr :: (b -> c) -> Kleisli m b c #

first :: Kleisli m b c -> Kleisli m (b, d) (c, d) #

second :: Kleisli m b c -> Kleisli m (d, b) (d, c) #

(***) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (b, b') (c, c') #

(&&&) :: Kleisli m b c -> Kleisli m b c' -> Kleisli m b (c, c') #

Applicative f => Arrow (A f) Source # 
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') #

Arrow (->) 
Instance details

Defined in Control.Arrow

Methods

arr :: (b -> c) -> b -> c #

first :: (b -> c) -> (b, d) -> (c, d) #

second :: (b -> c) -> (d, b) -> (d, c) #

(***) :: (b -> c) -> (b' -> c') -> (b, b') -> (c, c') #

(&&&) :: (b -> c) -> (b -> c') -> b -> (c, c') #

class ArrowZero a => ArrowPlus (a :: Type -> Type -> Type) where #

Methods

(<+>) :: a b c -> a b c -> a b c #

Instances

Instances details
MonadPlus m => ArrowPlus (Kleisli m) 
Instance details

Defined in Control.Arrow

Methods

(<+>) :: Kleisli m b c -> Kleisli m b c -> Kleisli m b c #

class Arrow a => ArrowLoop (a :: Type -> Type -> Type) where #

Methods

loop :: a (b, d) (c, d) -> a b c #

Instances

Instances details
MonadFix m => ArrowLoop (Kleisli m) 
Instance details

Defined in Control.Arrow

Methods

loop :: Kleisli m (b, d) (c, d) -> Kleisli m b c #

ArrowLoop (->) 
Instance details

Defined in Control.Arrow

Methods

loop :: ((b, d) -> (c, d)) -> b -> c #

class Arrow a => ArrowZero (a :: Type -> Type -> Type) where #

Methods

zeroArrow :: a b c #

Instances

Instances details
MonadPlus m => ArrowZero (Kleisli m) 
Instance details

Defined in Control.Arrow

Methods

zeroArrow :: Kleisli m b c #

(>>>) :: forall {k} cat (a :: k) (b :: k) (c :: k). Category cat => cat a b -> cat b c -> cat a c #

class Arrow a => ArrowChoice (a :: Type -> Type -> Type) where #

Minimal complete definition

(left | (+++))

Methods

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

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

(+++) :: a b c -> a b' c' -> a (Either b b') (Either c c') #

(|||) :: a b d -> a c d -> a (Either b c) d #

Instances

Instances details
Monad m => ArrowChoice (Kleisli m) 
Instance details

Defined in Control.Arrow

Methods

left :: Kleisli m b c -> Kleisli m (Either b d) (Either c d) #

right :: Kleisli m b c -> Kleisli m (Either d b) (Either d c) #

(+++) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (Either b b') (Either c c') #

(|||) :: Kleisli m b d -> Kleisli m c d -> Kleisli m (Either b c) d #

ArrowChoice (->) 
Instance details

Defined in Control.Arrow

Methods

left :: (b -> c) -> Either b d -> Either c d #

right :: (b -> c) -> Either d b -> Either d c #

(+++) :: (b -> c) -> (b' -> c') -> Either b b' -> Either c c' #

(|||) :: (b -> d) -> (c -> d) -> Either b c -> d #

class Arrow a => ArrowApply (a :: Type -> Type -> Type) where #

Methods

app :: a (a b c, b) c #

Instances

Instances details
Monad m => ArrowApply (Kleisli m) 
Instance details

Defined in Control.Arrow

Methods

app :: Kleisli m (Kleisli m b c, b) c #

ArrowApply (->) 
Instance details

Defined in Control.Arrow

Methods

app :: (b -> c, b) -> c #

(<<<) :: forall {k} cat (b :: k) (c :: k) (a :: k). Category cat => cat b c -> cat a b -> cat a c #

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

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

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

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

newtype Kleisli (m :: Type -> Type) a b #

Constructors

Kleisli 

Fields

Instances

Instances details
Monad m => Category (Kleisli m :: Type -> Type -> Type) 
Instance details

Defined in Control.Arrow

Methods

id :: Kleisli m a a

(.) :: Kleisli m b c -> Kleisli m a b -> Kleisli m a c

Generic1 (Kleisli m a :: Type -> Type) 
Instance details

Defined in Control.Arrow

Associated Types

type Rep1 (Kleisli m a :: Type -> Type) 
Instance details

Defined in Control.Arrow

type Rep1 (Kleisli m a :: Type -> Type) = D1 ('MetaData "Kleisli" "Control.Arrow" "base" 'True) (C1 ('MetaCons "Kleisli" 'PrefixI 'True) (S1 ('MetaSel ('Just "runKleisli") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) ((FUN 'Many a :: Type -> Type) :.: Rec1 m)))

Methods

from1 :: Kleisli m a a0 -> Rep1 (Kleisli m a) a0

to1 :: Rep1 (Kleisli m a) a0 -> Kleisli m a a0

Monad m => Arrow (Kleisli m) 
Instance details

Defined in Control.Arrow

Methods

arr :: (b -> c) -> Kleisli m b c #

first :: Kleisli m b c -> Kleisli m (b, d) (c, d) #

second :: Kleisli m b c -> Kleisli m (d, b) (d, c) #

(***) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (b, b') (c, c') #

(&&&) :: Kleisli m b c -> Kleisli m b c' -> Kleisli m b (c, c') #

Monad m => ArrowApply (Kleisli m) 
Instance details

Defined in Control.Arrow

Methods

app :: Kleisli m (Kleisli m b c, b) c #

Monad m => ArrowChoice (Kleisli m) 
Instance details

Defined in Control.Arrow

Methods

left :: Kleisli m b c -> Kleisli m (Either b d) (Either c d) #

right :: Kleisli m b c -> Kleisli m (Either d b) (Either d c) #

(+++) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (Either b b') (Either c c') #

(|||) :: Kleisli m b d -> Kleisli m c d -> Kleisli m (Either b c) d #

MonadFix m => ArrowLoop (Kleisli m) 
Instance details

Defined in Control.Arrow

Methods

loop :: Kleisli m (b, d) (c, d) -> Kleisli m b c #

MonadPlus m => ArrowPlus (Kleisli m) 
Instance details

Defined in Control.Arrow

Methods

(<+>) :: Kleisli m b c -> Kleisli m b c -> Kleisli m b c #

MonadPlus m => ArrowZero (Kleisli m) 
Instance details

Defined in Control.Arrow

Methods

zeroArrow :: Kleisli m b c #

Alternative m => Alternative (Kleisli m a) 
Instance details

Defined in Control.Arrow

Methods

empty :: Kleisli m a a0 #

(<|>) :: Kleisli m a a0 -> Kleisli m a a0 -> Kleisli m a a0 #

some :: Kleisli m a a0 -> Kleisli m a [a0] #

many :: Kleisli m a a0 -> Kleisli m a [a0] #

Applicative m => Applicative (Kleisli m a) 
Instance details

Defined in Control.Arrow

Methods

pure :: a0 -> Kleisli m a a0 #

(<*>) :: Kleisli m a (a0 -> b) -> Kleisli m a a0 -> Kleisli m a b #

liftA2 :: (a0 -> b -> c) -> Kleisli m a a0 -> Kleisli m a b -> Kleisli m a c #

(*>) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a b #

(<*) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a a0 #

Functor m => Functor (Kleisli m a) 
Instance details

Defined in Control.Arrow

Methods

fmap :: (a0 -> b) -> Kleisli m a a0 -> Kleisli m a b

(<$) :: a0 -> Kleisli m a b -> Kleisli m a a0 #

Monad m => Monad (Kleisli m a) 
Instance details

Defined in Control.Arrow

Methods

(>>=) :: Kleisli m a a0 -> (a0 -> Kleisli m a b) -> Kleisli m a b

(>>) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a b

return :: a0 -> Kleisli m a a0

MonadPlus m => MonadPlus (Kleisli m a) 
Instance details

Defined in Control.Arrow

Methods

mzero :: Kleisli m a a0

mplus :: Kleisli m a a0 -> Kleisli m a a0 -> Kleisli m a a0

Generic (Kleisli m a b) 
Instance details

Defined in Control.Arrow

Associated Types

type Rep (Kleisli m a b) 
Instance details

Defined in Control.Arrow

type Rep (Kleisli m a b) = D1 ('MetaData "Kleisli" "Control.Arrow" "base" 'True) (C1 ('MetaCons "Kleisli" 'PrefixI 'True) (S1 ('MetaSel ('Just "runKleisli") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (a -> m b))))

Methods

from :: Kleisli m a b -> Rep (Kleisli m a b) x

to :: Rep (Kleisli m a b) x -> Kleisli m a b

type Rep1 (Kleisli m a :: Type -> Type) 
Instance details

Defined in Control.Arrow

type Rep1 (Kleisli m a :: Type -> Type) = D1 ('MetaData "Kleisli" "Control.Arrow" "base" 'True) (C1 ('MetaCons "Kleisli" 'PrefixI 'True) (S1 ('MetaSel ('Just "runKleisli") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) ((FUN 'Many a :: Type -> Type) :.: Rec1 m)))
type Rep (Kleisli m a b) 
Instance details

Defined in Control.Arrow

type Rep (Kleisli m a b) = D1 ('MetaData "Kleisli" "Control.Arrow" "base" 'True) (C1 ('MetaCons "Kleisli" 'PrefixI 'True) (S1 ('MetaSel ('Just "runKleisli") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (a -> m b))))

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

Constructors

ArrowMonad (a () b) 

Instances

Instances details
ArrowPlus a => Alternative (ArrowMonad a) 
Instance details

Defined in Control.Arrow

Methods

empty :: ArrowMonad a a0 #

(<|>) :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 #

some :: ArrowMonad a a0 -> ArrowMonad a [a0] #

many :: ArrowMonad a a0 -> ArrowMonad a [a0] #

Arrow a => Applicative (ArrowMonad a) 
Instance details

Defined in Control.Arrow

Methods

pure :: a0 -> ArrowMonad a a0 #

(<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b #

liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c #

(*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b #

(<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 #

Arrow a => Functor (ArrowMonad a) 
Instance details

Defined in Control.Arrow

Methods

fmap :: (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b

(<$) :: a0 -> ArrowMonad a b -> ArrowMonad a a0 #

ArrowApply a => Monad (ArrowMonad a) 
Instance details

Defined in Control.Arrow

Methods

(>>=) :: ArrowMonad a a0 -> (a0 -> ArrowMonad a b) -> ArrowMonad a b

(>>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b

return :: a0 -> ArrowMonad a a0

(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) 
Instance details

Defined in Control.Arrow

Methods

mzero :: ArrowMonad a a0

mplus :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0

leftApp :: ArrowApply a => a b c -> a (Either b d) (Either c d) #

returnA :: Arrow a => a b b #

newtype A (f :: Type -> Type) a b Source #

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) Source # 
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) Source # 
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 Source #

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 Source #

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 Source #

The type of arrows associated to the applicative Parser functor.