| 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 verboseParser arrows, created out of regular Parser values using the asA
function, are arrows taking () as argument and returning the parsed value.
Synopsis
- (<<^) :: 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
- leftApp :: ArrowApply a => a b c -> a (Either b d) (Either c d)
- returnA :: Arrow a => a b b
- (<<<) :: forall {k} cat (b :: k) (c :: k) (a :: k). Category cat => cat b c -> cat a b -> cat a c
- (>>>) :: forall {k} cat (a :: k) (b :: k) (c :: k). Category cat => cat a b -> cat b c -> cat a c
- class Category a => Arrow (a :: Type -> Type -> Type) where
- class Arrow a => ArrowApply (a :: Type -> Type -> Type) where
- app :: a (a b c, b) c
- class Arrow a => ArrowChoice (a :: Type -> Type -> Type) where
- class Arrow a => ArrowLoop (a :: Type -> Type -> Type) where
- loop :: a (b, d) (c, d) -> a b c
- newtype ArrowMonad (a :: Type -> Type -> Type) b = ArrowMonad (a () b)
- class ArrowZero a => ArrowPlus (a :: Type -> Type -> Type) where
- (<+>) :: a b c -> a b c -> a b c
- class Arrow a => ArrowZero (a :: Type -> Type -> Type) where
- zeroArrow :: a b c
- newtype Kleisli (m :: Type -> Type) a b = Kleisli {
- runKleisli :: a -> m 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
leftApp :: ArrowApply a => a b c -> a (Either b d) (Either c d) #
class Category a => Arrow (a :: Type -> Type -> Type) where #
Methods
first :: a b c -> a (b, d) (c, d) #
second :: a b c -> a (d, b) (d, c) #
class Arrow a => ArrowApply (a :: Type -> Type -> Type) where #
Instances
| Monad m => ArrowApply (Kleisli m) # | |
Defined in GHC.Internal.Control.Arrow | |
| ArrowApply (->) # | |
Defined in GHC.Internal.Control.Arrow | |
class Arrow a => ArrowChoice (a :: Type -> Type -> Type) where #
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') #
Instances
| Monad m => ArrowChoice (Kleisli m) # | |
Defined in GHC.Internal.Control.Arrow | |
| ArrowChoice (->) # | |
newtype ArrowMonad (a :: Type -> Type -> Type) b #
Constructors
| ArrowMonad (a () b) |
Instances
newtype Kleisli (m :: Type -> Type) a b #
Constructors
| Kleisli | |
Fields
| |
Instances
| Monad m => Category (Kleisli m :: Type -> Type -> Type) # | |||||
| Generic1 (Kleisli m a :: Type -> Type) # | |||||
Defined in GHC.Internal.Control.Arrow Associated Types
| |||||
| Monad m => Arrow (Kleisli m) # | |||||
Defined in GHC.Internal.Control.Arrow | |||||
| Monad m => ArrowApply (Kleisli m) # | |||||
Defined in GHC.Internal.Control.Arrow | |||||
| Monad m => ArrowChoice (Kleisli m) # | |||||
Defined in GHC.Internal.Control.Arrow | |||||
| MonadFix m => ArrowLoop (Kleisli m) # | |||||
Defined in GHC.Internal.Control.Arrow | |||||
| MonadPlus m => ArrowPlus (Kleisli m) # | |||||
| MonadPlus m => ArrowZero (Kleisli m) # | |||||
Defined in GHC.Internal.Control.Arrow | |||||
| Alternative m => Alternative (Kleisli m a) # | |||||
| Applicative m => Applicative (Kleisli m a) # | |||||
Defined in GHC.Internal.Control.Arrow | |||||
| Functor m => Functor (Kleisli m a) # | |||||
| Monad m => Monad (Kleisli m a) # | |||||
| MonadPlus m => MonadPlus (Kleisli m a) # | |||||
| Generic (Kleisli m a b) # | |||||
Defined in GHC.Internal.Control.Arrow Associated Types
| |||||
| type Rep1 (Kleisli m a :: Type -> Type) # | |||||
Defined in GHC.Internal.Control.Arrow type Rep1 (Kleisli m a :: Type -> Type) = D1 ('MetaData "Kleisli" "GHC.Internal.Control.Arrow" "ghc-internal" '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) # | |||||
Defined in GHC.Internal.Control.Arrow type Rep (Kleisli m a b) = D1 ('MetaData "Kleisli" "GHC.Internal.Control.Arrow" "ghc-internal" 'True) (C1 ('MetaCons "Kleisli" 'PrefixI 'True) (S1 ('MetaSel ('Just "runKleisli") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (a -> m 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.
Instances
| Applicative f => Category (A f :: Type -> Type -> Type) Source # | |
| Applicative f => Arrow (A f) Source # | |
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.