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
- class Category a => Arrow (a :: Type -> Type -> Type) where
- 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
- zeroArrow :: a 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
- 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 {
- runKleisli :: a -> m b
- 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 #
Methods
first :: a b c -> a (b, d) (c, d) #
second :: a b c -> a (d, b) (d, c) #
Instances
Monad m => Arrow (Kleisli m) | |
Defined in Control.Arrow | |
Applicative f => Arrow (A f) Source # | |
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 Control.Arrow | |
ArrowChoice (->) | |
class Arrow a => ArrowApply (a :: Type -> Type -> Type) where #
Instances
Monad m => ArrowApply (Kleisli m) | |
Defined in Control.Arrow | |
ArrowApply (->) | |
Defined in Control.Arrow |
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 Control.Arrow Associated Types
| |||||
Monad m => Arrow (Kleisli m) | |||||
Defined in Control.Arrow | |||||
Monad m => ArrowApply (Kleisli m) | |||||
Defined in Control.Arrow | |||||
Monad m => ArrowChoice (Kleisli m) | |||||
Defined in Control.Arrow | |||||
MonadFix m => ArrowLoop (Kleisli m) | |||||
Defined in Control.Arrow | |||||
MonadPlus m => ArrowPlus (Kleisli m) | |||||
MonadPlus m => ArrowZero (Kleisli m) | |||||
Defined in Control.Arrow | |||||
Alternative m => Alternative (Kleisli m a) | |||||
Applicative m => Applicative (Kleisli m a) | |||||
Defined in 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 Control.Arrow Associated Types
| |||||
type Rep1 (Kleisli m a :: Type -> Type) | |||||
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) | |||||
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
leftApp :: ArrowApply a => a b c -> a (Either b d) (Either c d) #
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.