Copyright | Copyright © 2015 PivotCloud Inc. |
---|---|
License | MIT |
Maintainer | Lars Kuhtz <[email protected]> |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Configuration.Utils.CommandLine
Contents
Description
This module provides tools for defining command line parsers for configuration types.
Unlike normal command line parsers the parsers for configuration types are expected to yield an update function that takes a value and updates the value with the settings from the command line.
Assuming that
- all configuration types are nested Haskell records or simple types and
- that there are lenses for all record fields
usually the operators .::
and %::
are all that is needed from this module.
The module Configuration.Utils.Monoid provides tools for the case that
a simple type is a container with a monoid instance, such as List
or
HashMap
.
The module Configuration.Utils.Maybe explains the usage of optional
Maybe
values in configuration types.
Synopsis
- type MParser a = Parser (a -> a)
- (.::) :: (Alternative f, Applicative f) => Lens' a b -> f b -> f (a -> a)
- (%::) :: (Alternative f, Applicative f) => Lens' a b -> f (b -> b) -> f (a -> a)
- boolReader :: (Eq a, Show a, FoldCase a, IsString a, IsString e, Monoid e) => a -> Either e Bool
- boolOption :: Mod OptionFields Bool -> Parser Bool
- boolOption_ :: Mod FlagFields Bool -> Parser Bool
- enableDisableFlag :: Mod FlagFields Bool -> Parser Bool
- fileOption :: Mod OptionFields String -> Parser FilePath
- eitherReadP :: Text -> ReadP a -> Text -> Either Text a
- jsonOption :: FromJSON a => Mod OptionFields a -> Parser a
- jsonReader :: FromJSON a => ReadM a
- class Functor f => Applicative (f :: Type -> Type) where
- class Applicative f => Alternative (f :: Type -> Type) where
- newtype Const a (b :: k) = Const {
- getConst :: a
- data Mod (f :: Type -> Type) a
- newtype ZipList a = ZipList {
- getZipList :: [a]
- newtype WrappedArrow (a :: Type -> Type -> Type) b c = WrapArrow {
- unwrapArrow :: a b c
- newtype WrappedMonad (m :: Type -> Type) a = WrapMonad {
- unwrapMonad :: m a
- data ParserHelp = ParserHelp {
- helpError :: Chunk Doc
- helpSuggestions :: Chunk Doc
- helpHeader :: Chunk Doc
- helpUsage :: Chunk Doc
- helpDescription :: Chunk Doc
- helpBody :: Chunk Doc
- helpGlobals :: Chunk Doc
- helpFooter :: Chunk Doc
- data ParserResult a
- newtype ParserFailure h = ParserFailure {
- execFailure :: String -> (h, ExitCode, Int)
- newtype CompletionResult = CompletionResult {
- execCompletion :: String -> IO String
- data Completer
- data ReadM a
- data ParserPrefs = ParserPrefs {}
- data ParserInfo a = ParserInfo {
- infoParser :: Parser a
- infoFullDesc :: Bool
- infoProgDesc :: Chunk Doc
- infoHeader :: Chunk Doc
- infoFooter :: Chunk Doc
- infoFailureCode :: Int
- infoPolicy :: ArgPolicy
- data ParseError
- class HasMetavar (f :: Type -> Type)
- class HasValue (f :: Type -> Type)
- class HasCompleter (f :: Type -> Type)
- class HasName (f :: Type -> Type)
- data ArgumentFields a
- data CommandFields a
- data FlagFields a
- data OptionFields a
- data PrefsMod
- data InfoMod a
- info :: Parser a -> InfoMod a -> ParserInfo a
- option :: ReadM a -> Mod OptionFields a -> Parser a
- (<$) :: Functor f => a -> f b -> f a
- mappend :: Monoid a => a -> a -> a
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- optional :: Alternative f => f a -> f (Maybe a)
- short :: forall (f :: Type -> Type) a. HasName f => Char -> Mod f a
- value :: forall (f :: Type -> Type) a. HasValue f => a -> Mod f a
- (<**>) :: Applicative f => f a -> f (a -> b) -> f b
- liftA :: Applicative f => (a -> b) -> f a -> f b
- liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
- asum :: (Foldable t, Alternative f) => t (f a) -> f a
- readerAbort :: ParseError -> ReadM a
- readerError :: String -> ReadM a
- mkCompleter :: (String -> IO [String]) -> Completer
- overFailure :: (ParserHelp -> ParserHelp) -> ParserResult a -> ParserResult a
- briefDesc :: InfoMod a
- fullDesc :: InfoMod a
- internal :: forall (f :: Type -> Type) a. Mod f a
- listIOCompleter :: IO [String] -> Completer
- listCompleter :: [String] -> Completer
- bashCompleter :: String -> Completer
- auto :: Read a => ReadM a
- str :: IsString s => ReadM s
- eitherReader :: (String -> Either String a) -> ReadM a
- maybeReader :: (String -> Maybe a) -> ReadM a
- disabled :: ReadM a
- long :: forall (f :: Type -> Type) a. HasName f => String -> Mod f a
- showDefaultWith :: forall a (f :: Type -> Type). (a -> String) -> Mod f a
- showDefault :: forall a (f :: Type -> Type). Show a => Mod f a
- help :: forall (f :: Type -> Type) a. String -> Mod f a
- helpDoc :: forall (f :: Type -> Type) a. Maybe Doc -> Mod f a
- noArgError :: ParseError -> Mod OptionFields a
- metavar :: forall (f :: Type -> Type) a. HasMetavar f => String -> Mod f a
- hidden :: forall (f :: Type -> Type) a. Mod f a
- style :: forall (f :: Type -> Type) a. (Doc -> Doc) -> Mod f a
- command :: String -> ParserInfo a -> Mod CommandFields a
- commandGroup :: String -> Mod CommandFields a
- completeWith :: forall (f :: Type -> Type) a. HasCompleter f => [String] -> Mod f a
- action :: forall (f :: Type -> Type) a. HasCompleter f => String -> Mod f a
- completer :: forall (f :: Type -> Type) a. HasCompleter f => Completer -> Mod f a
- subparser :: Mod CommandFields a -> Parser a
- argument :: ReadM a -> Mod ArgumentFields a -> Parser a
- strArgument :: IsString s => Mod ArgumentFields s -> Parser s
- flag :: a -> a -> Mod FlagFields a -> Parser a
- flag' :: a -> Mod FlagFields a -> Parser a
- switch :: Mod FlagFields Bool -> Parser Bool
- abortOption :: ParseError -> Mod OptionFields (a -> a) -> Parser (a -> a)
- infoOption :: String -> Mod OptionFields (a -> a) -> Parser (a -> a)
- strOption :: IsString s => Mod OptionFields s -> Parser s
- header :: String -> InfoMod a
- headerDoc :: Maybe Doc -> InfoMod a
- footer :: String -> InfoMod a
- footerDoc :: Maybe Doc -> InfoMod a
- progDesc :: String -> InfoMod a
- progDescDoc :: Maybe Doc -> InfoMod a
- failureCode :: Int -> InfoMod a
- noIntersperse :: InfoMod a
- forwardOptions :: InfoMod a
- multiSuffix :: String -> PrefsMod
- disambiguate :: PrefsMod
- showHelpOnError :: PrefsMod
- showHelpOnEmpty :: PrefsMod
- noBacktrack :: PrefsMod
- subparserInline :: PrefsMod
- columns :: Int -> PrefsMod
- helpLongEquals :: PrefsMod
- helpShowGlobals :: PrefsMod
- helpIndent :: Int -> PrefsMod
- prefs :: PrefsMod -> ParserPrefs
- idm :: Monoid m => m
- defaultPrefs :: ParserPrefs
- helper :: Parser (a -> a)
- hsubparser :: Mod CommandFields a -> Parser a
- simpleVersioner :: String -> Parser (a -> a)
- execParser :: ParserInfo a -> IO a
- customExecParser :: ParserPrefs -> ParserInfo a -> IO a
- handleParseResult :: ParserResult a -> IO a
- getParseResult :: ParserResult a -> Maybe a
- execParserPure :: ParserPrefs -> ParserInfo a -> [String] -> ParserResult a
- parserFailure :: ParserPrefs -> ParserInfo a -> ParseError -> [Context] -> ParserFailure ParserHelp
- renderFailure :: ParserFailure ParserHelp -> String -> (String, ExitCode)
Documentation
(.::) :: (Alternative f, Applicative f) => Lens' a b -> f b -> f (a -> a) infixr 5 Source #
An operator for applying a setter to an option parser that yields a value.
Example usage:
data Auth = Auth { _user ∷ !String , _pwd ∷ !String } user ∷ Functor f ⇒ (String → f String) → Auth → f Auth user f s = (\u → s { _user = u }) <$> f (_user s) pwd ∷ Functor f ⇒ (String → f String) → Auth → f Auth pwd f s = (\p → s { _pwd = p }) <$> f (_pwd s) -- or with lenses and TemplateHaskell just: -- $(makeLenses ''Auth) pAuth ∷ MParser Auth pAuth = id <$< user .:: strOption % long "user" ⊕ short 'u' ⊕ help "user name" <*< pwd .:: strOption % long "pwd" ⊕ help "password for user"
(%::) :: (Alternative f, Applicative f) => Lens' a b -> f (b -> b) -> f (a -> a) infixr 5 Source #
An operator for applying a setter to an option parser that yields a modification function.
Example usage:
data HttpURL = HttpURL { _auth ∷ !Auth , _domain ∷ !String } auth ∷ Functor f ⇒ (Auth → f Auth) → HttpURL → f HttpURL auth f s = (\u → s { _auth = u }) <$> f (_auth s) domain ∷ Functor f ⇒ (String → f String) → HttpURL → f HttpURL domain f s = (\u → s { _domain = u }) <$> f (_domain s) path ∷ Functor f ⇒ (String → f String) → HttpURL → f HttpURL path f s = (\u → s { _path = u }) <$> f (_path s) -- or with lenses and TemplateHaskell just: -- $(makeLenses ''HttpURL) pHttpURL ∷ MParser HttpURL pHttpURL = id <$< auth %:: pAuth <*< domain .:: strOption % long "domain" ⊕ short 'd' ⊕ help "HTTP domain"
Misc Utils
boolReader :: (Eq a, Show a, FoldCase a, IsString a, IsString e, Monoid e) => a -> Either e Bool Source #
boolOption :: Mod OptionFields Bool -> Parser Bool Source #
The boolOption
is an alternative to switch
.
Using switch
with command line parsers that overwrite settings
from a configuration file is problematic: the absence of the switch
is interpreted as setting the respective configuration value to False
.
So there is no way to specify on the command line that the value from
the configuration file shall be used. Some command line UIs use two
different options for those values, for instance --enable-feature
and
--disable-feature
. This option instead expects a Boolean value. Beside
that it behaves like any other option.
boolOption_ :: Mod FlagFields Bool -> Parser Bool Source #
An alternative syntax for boolOption
for options with long names.
Instead of taking a boolean argument the presence of the option acts as a
switch to set the respective configuration setting to True
. If the option
is not present the setting is left unchanged.
In addition for long option names a respective unset flag is provided. For
instance for a flag --verbose
there will also be a flag --no-verbose
.
This can still be used with short option names only, but no unset flag would be provided.
enableDisableFlag :: Mod FlagFields Bool -> Parser Bool Source #
An option parser for flags that are enabled via the flag name prefixed
with --enable-
and disabled via the flag name prefix --disable-
. The
prefixes are applied to all long option names. Short option names are parsed
unchanged and cause the flag to be enabled.
This resembles the style of flags that is used for instances with Cabal.
fileOption :: Mod OptionFields String -> Parser FilePath Source #
An option that expects a file name.
eitherReadP :: Text -> ReadP a -> Text -> Either Text a Source #
Create an either-reader from a ReadP
parser.
jsonOption :: FromJSON a => Mod OptionFields a -> Parser a Source #
An option that expects a JSON value as argument.
jsonReader :: FromJSON a => ReadM a Source #
An option reader for a JSON value.
class Functor f => Applicative (f :: Type -> Type) where #
A functor with application, providing operations to
A minimal complete definition must include implementations of pure
and of either <*>
or liftA2
. If it defines both, then they must behave
the same as their default definitions:
(<*>
) =liftA2
id
liftA2
f x y = f<$>
x<*>
y
Further, any definition must satisfy the following:
- Identity
pure
id
<*>
v = v- Composition
pure
(.)<*>
u<*>
v<*>
w = u<*>
(v<*>
w)- Homomorphism
pure
f<*>
pure
x =pure
(f x)- Interchange
u
<*>
pure
y =pure
($
y)<*>
u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
As a consequence of these laws, the Functor
instance for f
will satisfy
It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2
p (liftA2
q u v) =liftA2
f u .liftA2
g v
If f
is also a Monad
, it should satisfy
(which implies that pure
and <*>
satisfy the applicative functor laws).
Methods
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
A few functors support an implementation of <*>
that is more
efficient than the default one.
Example
Used in combination with (
, <$>
)(
can be used to build a record.<*>
)
>>>
data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}
>>>
produceFoo :: Applicative f => f Foo
>>>
produceBar :: Applicative f => f Bar
>>>
produceBaz :: Applicative f => f Baz
>>>
mkState :: Applicative f => f MyState
>>>
mkState = MyState <$> produceFoo <*> produceBar <*> produceBaz
liftA2 :: (a -> b -> c) -> f a -> f b -> f c #
Lift a binary function to actions.
Some functors support an implementation of liftA2
that is more
efficient than the default one. In particular, if fmap
is an
expensive operation, it is likely better to use liftA2
than to
fmap
over the structure and then use <*>
.
This became a typeclass method in 4.10.0.0. Prior to that, it was
a function defined in terms of <*>
and fmap
.
Example
>>>
liftA2 (,) (Just 3) (Just 5)
Just (3,5)
(*>) :: f a -> f b -> f b infixl 4 #
Sequence actions, discarding the value of the first argument.
Examples
If used in conjunction with the Applicative instance for Maybe
,
you can chain Maybe computations, with a possible "early return"
in case of Nothing
.
>>>
Just 2 *> Just 3
Just 3
>>>
Nothing *> Just 3
Nothing
Of course a more interesting use case would be to have effectful computations instead of just returning pure values.
>>>
import Data.Char
>>>
import Text.ParserCombinators.ReadP
>>>
let p = string "my name is " *> munch1 isAlpha <* eof
>>>
readP_to_S p "my name is Simon"
[("Simon","")]
(<*) :: f a -> f b -> f a infixl 4 #
Sequence actions, discarding the value of the second argument.
Instances
Applicative Flag | |
Applicative Condition | |
Defined in Distribution.Types.Condition | |
Applicative IResult | |
Applicative Parser | |
Applicative Result | |
Applicative ZipList | f <$> ZipList xs1 <*> ... <*> ZipList xsN = ZipList (zipWithN f xs1 ... xsN) where (\a b c -> stimes c [a, b]) <$> ZipList "abcd" <*> ZipList "567" <*> ZipList [1..] = ZipList (zipWith3 (\a b c -> stimes c [a, b]) "abcd" "567" [1..]) = ZipList {getZipList = ["a5","b6b6","c7c7c7"]} Since: base-2.1 |
Applicative Complex | Since: base-4.9.0.0 |
Applicative Identity | Since: base-4.8.0.0 |
Applicative First | Since: base-4.8.0.0 |
Applicative Last | Since: base-4.8.0.0 |
Applicative First | Since: base-4.9.0.0 |
Applicative Last | Since: base-4.9.0.0 |
Applicative Max | Since: base-4.9.0.0 |
Applicative Min | Since: base-4.9.0.0 |
Applicative Dual | Since: base-4.8.0.0 |
Applicative Product | Since: base-4.8.0.0 |
Applicative Sum | Since: base-4.8.0.0 |
Applicative NonEmpty | Since: base-4.9.0.0 |
Applicative Par1 | Since: base-4.9.0.0 |
Applicative P | Since: base-4.5.0.0 |
Applicative ReadP | Since: base-4.6.0.0 |
Applicative ReadPrec | Since: base-4.6.0.0 |
Applicative Put | |
Applicative Seq | Since: containers-0.5.4 |
Applicative Tree | |
Applicative DNonEmpty | |
Defined in Data.DList.DNonEmpty.Internal | |
Applicative DList | |
Applicative IO | Since: base-2.1 |
Applicative Chunk | |
Applicative Parser | |
Applicative ParserM | |
Applicative ParserResult | |
Defined in Options.Applicative.Types Methods pure :: a -> ParserResult a # (<*>) :: ParserResult (a -> b) -> ParserResult a -> ParserResult b # liftA2 :: (a -> b -> c) -> ParserResult a -> ParserResult b -> ParserResult c # (*>) :: ParserResult a -> ParserResult b -> ParserResult b # (<*) :: ParserResult a -> ParserResult b -> ParserResult a # | |
Applicative ReadM | |
Applicative Array | |
Applicative SmallArray | |
Defined in Data.Primitive.SmallArray Methods pure :: a -> SmallArray a # (<*>) :: SmallArray (a -> b) -> SmallArray a -> SmallArray b # liftA2 :: (a -> b -> c) -> SmallArray a -> SmallArray b -> SmallArray c # (*>) :: SmallArray a -> SmallArray b -> SmallArray b # (<*) :: SmallArray a -> SmallArray b -> SmallArray a # | |
Applicative Q | |
Applicative Vector | |
Applicative Vector | |
Applicative Maybe | Since: base-2.1 |
Applicative Solo | Since: base-4.15 |
Applicative List | Since: base-2.1 |
Applicative (Parser i) | |
Monad m => Applicative (WrappedMonad m) | Since: base-2.1 |
Defined in Control.Applicative Methods pure :: a -> WrappedMonad m a # (<*>) :: WrappedMonad m (a -> b) -> WrappedMonad m a -> WrappedMonad m b # liftA2 :: (a -> b -> c) -> WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m c # (*>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # (<*) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m a # | |
Arrow a => Applicative (ArrowMonad a) | Since: base-4.6.0.0 |
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 # | |
Applicative (Either e) | Since: base-3.0 |
Applicative (U1 :: Type -> Type) | Since: base-4.9.0.0 |
Monad m => Applicative (ZipSource m) | |
Defined in Data.Conduit.Internal.Conduit | |
Applicative m => Applicative (ResourceT m) | |
Defined in Control.Monad.Trans.Resource.Internal | |
Semigroup a => Applicative (These a) | |
Semigroup a => Applicative (These a) | |
Applicative f => Applicative (Lift f) | A combination is |
(Functor m, Monad m) => Applicative (MaybeT m) | |
Monoid a => Applicative ((,) a) | For tuples, the ("hello ", (+15)) <*> ("world!", 2002) ("hello world!",2017) Since: base-2.1 |
Arrow a => Applicative (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative Methods pure :: a0 -> WrappedArrow a b a0 # (<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c # (*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 # (<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
Applicative m => Applicative (Kleisli m a) | Since: base-4.14.0.0 |
Defined in Control.Arrow | |
Monoid m => Applicative (Const m :: Type -> Type) | Since: base-2.0.1 |
Applicative f => Applicative (Ap f) | Since: base-4.12.0.0 |
Applicative f => Applicative (Alt f) | Since: base-4.8.0.0 |
(Generic1 f, Applicative (Rep1 f)) => Applicative (Generically1 f) | Since: base-4.17.0.0 |
Defined in GHC.Generics Methods pure :: a -> Generically1 f a # (<*>) :: Generically1 f (a -> b) -> Generically1 f a -> Generically1 f b # liftA2 :: (a -> b -> c) -> Generically1 f a -> Generically1 f b -> Generically1 f c # (*>) :: Generically1 f a -> Generically1 f b -> Generically1 f b # (<*) :: Generically1 f a -> Generically1 f b -> Generically1 f a # | |
Applicative f => Applicative (Rec1 f) | Since: base-4.9.0.0 |
Biapplicative p => Applicative (Join p) | |
Monad m => Applicative (ZipSink i m) | |
Defined in Data.Conduit.Internal.Conduit | |
(Applicative f, Monad f) => Applicative (WhenMissing f x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods pure :: a -> WhenMissing f x a # (<*>) :: WhenMissing f x (a -> b) -> WhenMissing f x a -> WhenMissing f x b # liftA2 :: (a -> b -> c) -> WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x c # (*>) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x b # (<*) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x a # | |
(Profunctor p, Arrow p) => Applicative (Closure p a) | |
Defined in Data.Profunctor.Closed | |
(Profunctor p, Arrow p) => Applicative (Tambara p a) | |
Defined in Data.Profunctor.Strong | |
Applicative (Tagged s) | |
Applicative f => Applicative (Backwards f) | Apply |
Defined in Control.Applicative.Backwards | |
(Monoid w, Functor m, Monad m) => Applicative (AccumT w m) | |
Defined in Control.Monad.Trans.Accum | |
(Functor m, Monad m) => Applicative (ExceptT e m) | |
Defined in Control.Monad.Trans.Except | |
Applicative m => Applicative (IdentityT m) | |
Defined in Control.Monad.Trans.Identity | |
Applicative m => Applicative (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
(Functor m, Monad m) => Applicative (SelectT r m) | |
Defined in Control.Monad.Trans.Select | |
(Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Lazy | |
(Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
(Functor m, Monad m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.CPS | |
(Monoid w, Applicative m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Lazy | |
(Monoid w, Applicative m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Strict | |
Monoid a => Applicative (Constant a :: Type -> Type) | |
Defined in Data.Functor.Constant | |
Applicative f => Applicative (Reverse f) | Derived instance. |
(Monoid a, Monoid b) => Applicative ((,,) a b) | Since: base-4.14.0.0 |
(Applicative f, Applicative g) => Applicative (Product f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Product | |
(Applicative f, Applicative g) => Applicative (f :*: g) | Since: base-4.9.0.0 |
Monoid c => Applicative (K1 i c :: Type -> Type) | Since: base-4.12.0.0 |
Applicative (ConduitT i o m) | |
Defined in Data.Conduit.Internal.Conduit Methods pure :: a -> ConduitT i o m a # (<*>) :: ConduitT i o m (a -> b) -> ConduitT i o m a -> ConduitT i o m b # liftA2 :: (a -> b -> c) -> ConduitT i o m a -> ConduitT i o m b -> ConduitT i o m c # (*>) :: ConduitT i o m a -> ConduitT i o m b -> ConduitT i o m b # (<*) :: ConduitT i o m a -> ConduitT i o m b -> ConduitT i o m a # | |
Monad m => Applicative (ZipConduit i o m) | |
Defined in Data.Conduit.Internal.Conduit Methods pure :: a -> ZipConduit i o m a # (<*>) :: ZipConduit i o m (a -> b) -> ZipConduit i o m a -> ZipConduit i o m b # liftA2 :: (a -> b -> c) -> ZipConduit i o m a -> ZipConduit i o m b -> ZipConduit i o m c # (*>) :: ZipConduit i o m a -> ZipConduit i o m b -> ZipConduit i o m b # (<*) :: ZipConduit i o m a -> ZipConduit i o m b -> ZipConduit i o m a # | |
(Monad f, Applicative f) => Applicative (WhenMatched f x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods pure :: a -> WhenMatched f x y a # (<*>) :: WhenMatched f x y (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b # liftA2 :: (a -> b -> c) -> WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y c # (*>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b # (<*) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y a # | |
(Applicative f, Monad f) => Applicative (WhenMissing f k x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods pure :: a -> WhenMissing f k x a # (<*>) :: WhenMissing f k x (a -> b) -> WhenMissing f k x a -> WhenMissing f k x b # liftA2 :: (a -> b -> c) -> WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x c # (*>) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x b # (<*) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x a # | |
Applicative (Costar f a) | |
Defined in Data.Profunctor.Types | |
Applicative f => Applicative (Star f a) | |
Applicative (ContT r m) | |
Defined in Control.Monad.Trans.Cont | |
(Monoid a, Monoid b, Monoid c) => Applicative ((,,,) a b c) | Since: base-4.14.0.0 |
Defined in GHC.Base | |
Applicative ((->) r) | Since: base-2.1 |
(Applicative f, Applicative g) => Applicative (Compose f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose | |
(Applicative f, Applicative g) => Applicative (f :.: g) | Since: base-4.9.0.0 |
Applicative f => Applicative (M1 i c f) | Since: base-4.9.0.0 |
(Monad f, Applicative f) => Applicative (WhenMatched f k x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods pure :: a -> WhenMatched f k x y a # (<*>) :: WhenMatched f k x y (a -> b) -> WhenMatched f k x y a -> WhenMatched f k x y b # liftA2 :: (a -> b -> c) -> WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y c # (*>) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y b # (<*) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y a # | |
(Functor m, Monad m) => Applicative (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.CPS | |
(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.Lazy | |
(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.Strict | |
Monad m => Applicative (Pipe l i o u m) | |
Defined in Data.Conduit.Internal.Pipe Methods pure :: a -> Pipe l i o u m a # (<*>) :: Pipe l i o u m (a -> b) -> Pipe l i o u m a -> Pipe l i o u m b # liftA2 :: (a -> b -> c) -> Pipe l i o u m a -> Pipe l i o u m b -> Pipe l i o u m c # (*>) :: Pipe l i o u m a -> Pipe l i o u m b -> Pipe l i o u m b # (<*) :: Pipe l i o u m a -> Pipe l i o u m b -> Pipe l i o u m a # |
class Applicative f => Alternative (f :: Type -> Type) where #
A monoid on applicative functors.
If defined, some
and many
should be the least solutions
of the equations:
Methods
The identity of <|>
(<|>) :: f a -> f a -> f a infixl 3 #
An associative binary operation
One or more.
Zero or more.
Instances
The Const
functor.
Instances
Generic1 (Const a :: k -> Type) | |
Unbox a => Vector Vector (Const a b) | |
Defined in Data.Vector.Unboxed.Base Methods basicUnsafeFreeze :: Mutable Vector s (Const a b) -> ST s (Vector (Const a b)) basicUnsafeThaw :: Vector (Const a b) -> ST s (Mutable Vector s (Const a b)) basicLength :: Vector (Const a b) -> Int basicUnsafeSlice :: Int -> Int -> Vector (Const a b) -> Vector (Const a b) basicUnsafeIndexM :: Vector (Const a b) -> Int -> Box (Const a b) basicUnsafeCopy :: Mutable Vector s (Const a b) -> Vector (Const a b) -> ST s () | |
Unbox a => MVector MVector (Const a b) | |
Defined in Data.Vector.Unboxed.Base Methods basicLength :: MVector s (Const a b) -> Int basicUnsafeSlice :: Int -> Int -> MVector s (Const a b) -> MVector s (Const a b) basicOverlaps :: MVector s (Const a b) -> MVector s (Const a b) -> Bool basicUnsafeNew :: Int -> ST s (MVector s (Const a b)) basicInitialize :: MVector s (Const a b) -> ST s () basicUnsafeReplicate :: Int -> Const a b -> ST s (MVector s (Const a b)) basicUnsafeRead :: MVector s (Const a b) -> Int -> ST s (Const a b) basicUnsafeWrite :: MVector s (Const a b) -> Int -> Const a b -> ST s () basicClear :: MVector s (Const a b) -> ST s () basicSet :: MVector s (Const a b) -> Const a b -> ST s () basicUnsafeCopy :: MVector s (Const a b) -> MVector s (Const a b) -> ST s () basicUnsafeMove :: MVector s (Const a b) -> MVector s (Const a b) -> ST s () basicUnsafeGrow :: MVector s (Const a b) -> Int -> ST s (MVector s (Const a b)) | |
FromJSON2 (Const :: Type -> Type -> Type) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: Maybe a -> (Value -> Parser a) -> (Value -> Parser [a]) -> Maybe b -> (Value -> Parser b) -> (Value -> Parser [b]) -> Value -> Parser (Const a b) # liftParseJSONList2 :: Maybe a -> (Value -> Parser a) -> (Value -> Parser [a]) -> Maybe b -> (Value -> Parser b) -> (Value -> Parser [b]) -> Value -> Parser [Const a b] # liftOmittedField2 :: Maybe a -> Maybe b -> Maybe (Const a b) # | |
ToJSON2 (Const :: Type -> Type -> Type) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a -> Bool) -> (a -> Value) -> ([a] -> Value) -> (b -> Bool) -> (b -> Value) -> ([b] -> Value) -> Const a b -> Value # liftToJSONList2 :: (a -> Bool) -> (a -> Value) -> ([a] -> Value) -> (b -> Bool) -> (b -> Value) -> ([b] -> Value) -> [Const a b] -> Value # liftToEncoding2 :: (a -> Bool) -> (a -> Encoding) -> ([a] -> Encoding) -> (b -> Bool) -> (b -> Encoding) -> ([b] -> Encoding) -> Const a b -> Encoding # liftToEncodingList2 :: (a -> Bool) -> (a -> Encoding) -> ([a] -> Encoding) -> (b -> Bool) -> (b -> Encoding) -> ([b] -> Encoding) -> [Const a b] -> Encoding # liftOmitField2 :: (a -> Bool) -> (b -> Bool) -> Const a b -> Bool # | |
Bifunctor (Const :: Type -> Type -> Type) | Since: base-4.8.0.0 |
NFData2 (Const :: Type -> Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Hashable2 (Const :: Type -> Type -> Type) | |
Defined in Data.Hashable.Class | |
FromJSON a => FromJSON1 (Const a :: Type -> Type) | |
Defined in Data.Aeson.Types.FromJSON | |
ToJSON a => ToJSON1 (Const a :: Type -> Type) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Bool) -> (a0 -> Value) -> ([a0] -> Value) -> Const a a0 -> Value # liftToJSONList :: (a0 -> Bool) -> (a0 -> Value) -> ([a0] -> Value) -> [Const a a0] -> Value # liftToEncoding :: (a0 -> Bool) -> (a0 -> Encoding) -> ([a0] -> Encoding) -> Const a a0 -> Encoding # liftToEncodingList :: (a0 -> Bool) -> (a0 -> Encoding) -> ([a0] -> Encoding) -> [Const a a0] -> Encoding # liftOmitField :: (a0 -> Bool) -> Const a a0 -> Bool # | |
Foldable (Const m :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Functor.Const Methods fold :: Monoid m0 => Const m m0 -> m0 # foldMap :: Monoid m0 => (a -> m0) -> Const m a -> m0 # foldMap' :: Monoid m0 => (a -> m0) -> Const m a -> m0 # foldr :: (a -> b -> b) -> b -> Const m a -> b # foldr' :: (a -> b -> b) -> b -> Const m a -> b # foldl :: (b -> a -> b) -> b -> Const m a -> b # foldl' :: (b -> a -> b) -> b -> Const m a -> b # foldr1 :: (a -> a -> a) -> Const m a -> a # foldl1 :: (a -> a -> a) -> Const m a -> a # elem :: Eq a => a -> Const m a -> Bool # maximum :: Ord a => Const m a -> a # minimum :: Ord a => Const m a -> a # | |
Traversable (Const m :: Type -> Type) | Since: base-4.7.0.0 |
Monoid m => Applicative (Const m :: Type -> Type) | Since: base-2.0.1 |
Functor (Const m :: Type -> Type) | Since: base-2.1 |
NFData a => NFData1 (Const a :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Hashable a => Hashable1 (Const a :: Type -> Type) | |
Defined in Data.Hashable.Class | |
FromJSON a => FromJSON (Const a b) | |
Defined in Data.Aeson.Types.FromJSON | |
(FromJSON a, FromJSONKey a) => FromJSONKey (Const a b) | |
Defined in Data.Aeson.Types.FromJSON Methods fromJSONKey :: FromJSONKeyFunction (Const a b) # fromJSONKeyList :: FromJSONKeyFunction [Const a b] # | |
ToJSON a => ToJSON (Const a b) | |
(ToJSON a, ToJSONKey a) => ToJSONKey (Const a b) | |
Defined in Data.Aeson.Types.ToJSON | |
IsString a => IsString (Const a b) | Since: base-4.9.0.0 |
Defined in Data.String Methods fromString :: String -> Const a b # | |
Storable a => Storable (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
Monoid a => Monoid (Const a b) | Since: base-4.9.0.0 |
Semigroup a => Semigroup (Const a b) | Since: base-4.9.0.0 |
Bits a => Bits (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods (.&.) :: Const a b -> Const a b -> Const a b # (.|.) :: Const a b -> Const a b -> Const a b # xor :: Const a b -> Const a b -> Const a b # complement :: Const a b -> Const a b # shift :: Const a b -> Int -> Const a b # rotate :: Const a b -> Int -> Const a b # setBit :: Const a b -> Int -> Const a b # clearBit :: Const a b -> Int -> Const a b # complementBit :: Const a b -> Int -> Const a b # testBit :: Const a b -> Int -> Bool # bitSizeMaybe :: Const a b -> Maybe Int # isSigned :: Const a b -> Bool # shiftL :: Const a b -> Int -> Const a b # unsafeShiftL :: Const a b -> Int -> Const a b # shiftR :: Const a b -> Int -> Const a b # unsafeShiftR :: Const a b -> Int -> Const a b # rotateL :: Const a b -> Int -> Const a b # | |
FiniteBits a => FiniteBits (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods finiteBitSize :: Const a b -> Int # countLeadingZeros :: Const a b -> Int # countTrailingZeros :: Const a b -> Int # | |
Bounded a => Bounded (Const a b) | Since: base-4.9.0.0 |
Enum a => Enum (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods succ :: Const a b -> Const a b # pred :: Const a b -> Const a b # fromEnum :: Const a b -> Int # enumFrom :: Const a b -> [Const a b] # enumFromThen :: Const a b -> Const a b -> [Const a b] # enumFromTo :: Const a b -> Const a b -> [Const a b] # enumFromThenTo :: Const a b -> Const a b -> Const a b -> [Const a b] # | |
Floating a => Floating (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods exp :: Const a b -> Const a b # log :: Const a b -> Const a b # sqrt :: Const a b -> Const a b # (**) :: Const a b -> Const a b -> Const a b # logBase :: Const a b -> Const a b -> Const a b # sin :: Const a b -> Const a b # cos :: Const a b -> Const a b # tan :: Const a b -> Const a b # asin :: Const a b -> Const a b # acos :: Const a b -> Const a b # atan :: Const a b -> Const a b # sinh :: Const a b -> Const a b # cosh :: Const a b -> Const a b # tanh :: Const a b -> Const a b # asinh :: Const a b -> Const a b # acosh :: Const a b -> Const a b # atanh :: Const a b -> Const a b # log1p :: Const a b -> Const a b # expm1 :: Const a b -> Const a b # | |
RealFloat a => RealFloat (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods floatRadix :: Const a b -> Integer # floatDigits :: Const a b -> Int # floatRange :: Const a b -> (Int, Int) # decodeFloat :: Const a b -> (Integer, Int) # encodeFloat :: Integer -> Int -> Const a b # exponent :: Const a b -> Int # significand :: Const a b -> Const a b # scaleFloat :: Int -> Const a b -> Const a b # isInfinite :: Const a b -> Bool # isDenormalized :: Const a b -> Bool # isNegativeZero :: Const a b -> Bool # | |
Generic (Const a b) | |
Ix a => Ix (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods range :: (Const a b, Const a b) -> [Const a b] # index :: (Const a b, Const a b) -> Const a b -> Int # unsafeIndex :: (Const a b, Const a b) -> Const a b -> Int # inRange :: (Const a b, Const a b) -> Const a b -> Bool # rangeSize :: (Const a b, Const a b) -> Int # unsafeRangeSize :: (Const a b, Const a b) -> Int # | |
Num a => Num (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
Read a => Read (Const a b) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
Fractional a => Fractional (Const a b) | Since: base-4.9.0.0 |
Integral a => Integral (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods quot :: Const a b -> Const a b -> Const a b # rem :: Const a b -> Const a b -> Const a b # div :: Const a b -> Const a b -> Const a b # mod :: Const a b -> Const a b -> Const a b # quotRem :: Const a b -> Const a b -> (Const a b, Const a b) # divMod :: Const a b -> Const a b -> (Const a b, Const a b) # | |
Real a => Real (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods toRational :: Const a b -> Rational # | |
RealFrac a => RealFrac (Const a b) | Since: base-4.9.0.0 |
Show a => Show (Const a b) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
NFData a => NFData (Const a b) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq a => Eq (Const a b) | Since: base-4.9.0.0 |
Ord a => Ord (Const a b) | Since: base-4.9.0.0 |
Hashable a => Hashable (Const a b) | |
Defined in Data.Hashable.Class | |
Pretty a => Pretty (Const a b) | |
Defined in Prettyprinter.Internal | |
Unbox a => Unbox (Const a b) | |
Defined in Data.Vector.Unboxed.Base | |
type Rep1 (Const a :: k -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
newtype MVector s (Const a b) | |
Defined in Data.Vector.Unboxed.Base | |
type Rep (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
newtype Vector (Const a b) | |
Defined in Data.Vector.Unboxed.Base |
data Mod (f :: Type -> Type) a #
An option modifier.
Option modifiers are values that represent a modification of the properties of an option.
The type parameter a
is the return type of the option, while f
is a
record containing its properties (e.g. OptionFields
for regular options,
FlagFields
for flags, etc...).
An option modifier consists of 3 elements:
- A field modifier, of the form
f a -> f a
. These are essentially (compositions of) setters for some of the properties supported byf
. - An optional default value and function to display it.
- A property modifier, of the form
OptProperties -> OptProperties
. This is just like the field modifier, but for properties applicable to any option.
Modifiers are instances of Monoid
, and can be composed as such.
One rarely needs to deal with modifiers directly, as most of the times it is
sufficient to pass them to builders (such as strOption
or flag
) to
create options (see Builder
).
Lists, but with an Applicative
functor based on zipping.
Constructors
ZipList | |
Fields
|
Instances
Foldable ZipList | Since: base-4.9.0.0 |
Defined in Control.Applicative Methods fold :: Monoid m => ZipList m -> m # foldMap :: Monoid m => (a -> m) -> ZipList a -> m # foldMap' :: Monoid m => (a -> m) -> ZipList a -> m # foldr :: (a -> b -> b) -> b -> ZipList a -> b # foldr' :: (a -> b -> b) -> b -> ZipList a -> b # foldl :: (b -> a -> b) -> b -> ZipList a -> b # foldl' :: (b -> a -> b) -> b -> ZipList a -> b # foldr1 :: (a -> a -> a) -> ZipList a -> a # foldl1 :: (a -> a -> a) -> ZipList a -> a # elem :: Eq a => a -> ZipList a -> Bool # maximum :: Ord a => ZipList a -> a # minimum :: Ord a => ZipList a -> a # | |
Traversable ZipList | Since: base-4.9.0.0 |
Alternative ZipList | Since: base-4.11.0.0 |
Applicative ZipList | f <$> ZipList xs1 <*> ... <*> ZipList xsN = ZipList (zipWithN f xs1 ... xsN) where (\a b c -> stimes c [a, b]) <$> ZipList "abcd" <*> ZipList "567" <*> ZipList [1..] = ZipList (zipWith3 (\a b c -> stimes c [a, b]) "abcd" "567" [1..]) = ZipList {getZipList = ["a5","b6b6","c7c7c7"]} Since: base-2.1 |
Functor ZipList | Since: base-2.1 |
NFData1 ZipList | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Generic1 ZipList | |
Generic (ZipList a) | |
IsList (ZipList a) | Since: base-4.15.0.0 |
Read a => Read (ZipList a) | Since: base-4.7.0.0 |
Show a => Show (ZipList a) | Since: base-4.7.0.0 |
NFData a => NFData (ZipList a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq a => Eq (ZipList a) | Since: base-4.7.0.0 |
Ord a => Ord (ZipList a) | Since: base-4.7.0.0 |
type Rep1 ZipList | Since: base-4.7.0.0 |
Defined in Control.Applicative | |
type Rep (ZipList a) | Since: base-4.7.0.0 |
Defined in Control.Applicative | |
type Item (ZipList a) | |
Defined in GHC.IsList |
newtype WrappedArrow (a :: Type -> Type -> Type) b c #
Constructors
WrapArrow | |
Fields
|
Instances
Generic1 (WrappedArrow a b :: Type -> Type) | |
Defined in Control.Applicative Associated Types type Rep1 (WrappedArrow a b) :: k -> Type # Methods from1 :: forall (a0 :: k). WrappedArrow a b a0 -> Rep1 (WrappedArrow a b) a0 # to1 :: forall (a0 :: k). Rep1 (WrappedArrow a b) a0 -> WrappedArrow a b a0 # | |
(ArrowZero a, ArrowPlus a) => Alternative (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative Methods empty :: WrappedArrow a b a0 # (<|>) :: WrappedArrow a b a0 -> WrappedArrow a b a0 -> WrappedArrow a b a0 # some :: WrappedArrow a b a0 -> WrappedArrow a b [a0] # many :: WrappedArrow a b a0 -> WrappedArrow a b [a0] # | |
Arrow a => Applicative (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative Methods pure :: a0 -> WrappedArrow a b a0 # (<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c # (*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 # (<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
Arrow a => Functor (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative Methods fmap :: (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # (<$) :: a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
Generic (WrappedArrow a b c) | |
Defined in Control.Applicative Associated Types type Rep (WrappedArrow a b c) :: Type -> Type # Methods from :: WrappedArrow a b c -> Rep (WrappedArrow a b c) x # to :: Rep (WrappedArrow a b c) x -> WrappedArrow a b c # | |
type Rep1 (WrappedArrow a b :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Control.Applicative type Rep1 (WrappedArrow a b :: Type -> Type) = D1 ('MetaData "WrappedArrow" "Control.Applicative" "base" 'True) (C1 ('MetaCons "WrapArrow" 'PrefixI 'True) (S1 ('MetaSel ('Just "unwrapArrow") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 (a b)))) | |
type Rep (WrappedArrow a b c) | Since: base-4.7.0.0 |
Defined in Control.Applicative type Rep (WrappedArrow a b c) = D1 ('MetaData "WrappedArrow" "Control.Applicative" "base" 'True) (C1 ('MetaCons "WrapArrow" 'PrefixI 'True) (S1 ('MetaSel ('Just "unwrapArrow") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (a b c)))) |
newtype WrappedMonad (m :: Type -> Type) a #
Constructors
WrapMonad | |
Fields
|
Instances
data ParserHelp #
Constructors
ParserHelp | |
Fields
|
Instances
Monoid ParserHelp | |
Defined in Options.Applicative.Help.Types Methods mempty :: ParserHelp # mappend :: ParserHelp -> ParserHelp -> ParserHelp # mconcat :: [ParserHelp] -> ParserHelp # | |
Semigroup ParserHelp | |
Defined in Options.Applicative.Help.Types Methods (<>) :: ParserHelp -> ParserHelp -> ParserHelp # sconcat :: NonEmpty ParserHelp -> ParserHelp # stimes :: Integral b => b -> ParserHelp -> ParserHelp # | |
Show ParserHelp | |
Defined in Options.Applicative.Help.Types Methods showsPrec :: Int -> ParserHelp -> ShowS # show :: ParserHelp -> String # showList :: [ParserHelp] -> ShowS # |
data ParserResult a #
Result of execParserPure
.
Constructors
Failure (ParserFailure ParserHelp) | |
CompletionInvoked CompletionResult |
Instances
Applicative ParserResult | |
Defined in Options.Applicative.Types Methods pure :: a -> ParserResult a # (<*>) :: ParserResult (a -> b) -> ParserResult a -> ParserResult b # liftA2 :: (a -> b -> c) -> ParserResult a -> ParserResult b -> ParserResult c # (*>) :: ParserResult a -> ParserResult b -> ParserResult b # (<*) :: ParserResult a -> ParserResult b -> ParserResult a # | |
Functor ParserResult | |
Defined in Options.Applicative.Types Methods fmap :: (a -> b) -> ParserResult a -> ParserResult b # (<$) :: a -> ParserResult b -> ParserResult a # | |
Monad ParserResult | |
Defined in Options.Applicative.Types Methods (>>=) :: ParserResult a -> (a -> ParserResult b) -> ParserResult b # (>>) :: ParserResult a -> ParserResult b -> ParserResult b # return :: a -> ParserResult a # | |
Show a => Show (ParserResult a) | |
Defined in Options.Applicative.Types Methods showsPrec :: Int -> ParserResult a -> ShowS # show :: ParserResult a -> String # showList :: [ParserResult a] -> ShowS # |
newtype ParserFailure h #
Constructors
ParserFailure | |
Fields
|
Instances
Functor ParserFailure | |
Defined in Options.Applicative.Types Methods fmap :: (a -> b) -> ParserFailure a -> ParserFailure b # (<$) :: a -> ParserFailure b -> ParserFailure a # | |
Show h => Show (ParserFailure h) | |
Defined in Options.Applicative.Types Methods showsPrec :: Int -> ParserFailure h -> ShowS # show :: ParserFailure h -> String # showList :: [ParserFailure h] -> ShowS # |
newtype CompletionResult #
Constructors
CompletionResult | |
Fields
|
Instances
Show CompletionResult | |
Defined in Options.Applicative.Types Methods showsPrec :: Int -> CompletionResult -> ShowS # show :: CompletionResult -> String # showList :: [CompletionResult] -> ShowS # |
A newtype over 'ReaderT String Except', used by option readers.
Instances
data ParserPrefs #
Global preferences for a top-level Parser
.
Constructors
ParserPrefs | |
Fields
|
Instances
Show ParserPrefs | |
Defined in Options.Applicative.Types Methods showsPrec :: Int -> ParserPrefs -> ShowS # show :: ParserPrefs -> String # showList :: [ParserPrefs] -> ShowS # | |
Eq ParserPrefs | |
Defined in Options.Applicative.Types |
data ParserInfo a #
A full description for a runnable Parser
for a program.
Constructors
ParserInfo | |
Fields
|
Instances
Functor ParserInfo | |
Defined in Options.Applicative.Types Methods fmap :: (a -> b) -> ParserInfo a -> ParserInfo b # (<$) :: a -> ParserInfo b -> ParserInfo a # |
data ParseError #
Constructors
ErrorMsg String | |
InfoMsg String | |
ShowHelpText (Maybe String) | |
UnknownError | |
MissingError IsCmdStart SomeParser | |
ExpectsArgError String | |
UnexpectedError String SomeParser |
Instances
Monoid ParseError | |
Defined in Options.Applicative.Types Methods mempty :: ParseError # mappend :: ParseError -> ParseError -> ParseError # mconcat :: [ParseError] -> ParseError # | |
Semigroup ParseError | |
Defined in Options.Applicative.Types Methods (<>) :: ParseError -> ParseError -> ParseError # sconcat :: NonEmpty ParseError -> ParseError # stimes :: Integral b => b -> ParseError -> ParseError # |
class HasMetavar (f :: Type -> Type) #
Minimal complete definition
Instances
HasMetavar ArgumentFields | |
Defined in Options.Applicative.Builder.Internal Methods hasMetavarDummy :: ArgumentFields a -> () # | |
HasMetavar CommandFields | |
Defined in Options.Applicative.Builder.Internal Methods hasMetavarDummy :: CommandFields a -> () # | |
HasMetavar OptionFields | |
Defined in Options.Applicative.Builder.Internal Methods hasMetavarDummy :: OptionFields a -> () # |
class HasValue (f :: Type -> Type) #
Minimal complete definition
Instances
HasValue ArgumentFields | |
Defined in Options.Applicative.Builder.Internal Methods hasValueDummy :: ArgumentFields a -> () # | |
HasValue OptionFields | |
Defined in Options.Applicative.Builder.Internal Methods hasValueDummy :: OptionFields a -> () # |
class HasCompleter (f :: Type -> Type) #
Minimal complete definition
Instances
HasCompleter ArgumentFields | |
Defined in Options.Applicative.Builder.Internal Methods modCompleter :: (Completer -> Completer) -> ArgumentFields a -> ArgumentFields a # | |
HasCompleter OptionFields | |
Defined in Options.Applicative.Builder.Internal Methods modCompleter :: (Completer -> Completer) -> OptionFields a -> OptionFields a # |
class HasName (f :: Type -> Type) #
Minimal complete definition
Instances
HasName FlagFields | |
Defined in Options.Applicative.Builder.Internal Methods name :: OptName -> FlagFields a -> FlagFields a # | |
HasName OptionFields | |
Defined in Options.Applicative.Builder.Internal Methods name :: OptName -> OptionFields a -> OptionFields a # |
data ArgumentFields a #
Instances
HasCompleter ArgumentFields | |
Defined in Options.Applicative.Builder.Internal Methods modCompleter :: (Completer -> Completer) -> ArgumentFields a -> ArgumentFields a # | |
HasMetavar ArgumentFields | |
Defined in Options.Applicative.Builder.Internal Methods hasMetavarDummy :: ArgumentFields a -> () # | |
HasValue ArgumentFields | |
Defined in Options.Applicative.Builder.Internal Methods hasValueDummy :: ArgumentFields a -> () # |
data CommandFields a #
Instances
HasMetavar CommandFields | |
Defined in Options.Applicative.Builder.Internal Methods hasMetavarDummy :: CommandFields a -> () # |
data FlagFields a #
Instances
HasName FlagFields | |
Defined in Options.Applicative.Builder.Internal Methods name :: OptName -> FlagFields a -> FlagFields a # |
data OptionFields a #
Instances
HasCompleter OptionFields | |
Defined in Options.Applicative.Builder.Internal Methods modCompleter :: (Completer -> Completer) -> OptionFields a -> OptionFields a # | |
HasMetavar OptionFields | |
Defined in Options.Applicative.Builder.Internal Methods hasMetavarDummy :: OptionFields a -> () # | |
HasName OptionFields | |
Defined in Options.Applicative.Builder.Internal Methods name :: OptName -> OptionFields a -> OptionFields a # | |
HasValue OptionFields | |
Defined in Options.Applicative.Builder.Internal Methods hasValueDummy :: OptionFields a -> () # |
Modifier for ParserInfo
.
info :: Parser a -> InfoMod a -> ParserInfo a #
Create a ParserInfo
given a Parser
and a modifier.
option :: ReadM a -> Mod OptionFields a -> Parser a #
Builder for an option using the given reader.
This is a regular option, and should always have either a long
or
short
name specified in the modifiers (or both).
nameParser = option str ( long "name" <> short 'n' )
mappend :: Monoid a => a -> a -> a #
An associative operation
NOTE: This method is redundant and has the default
implementation
since base-4.11.0.0.
Should it be implemented manually, since mappend
= (<>
)mappend
is a synonym for
(<>
), it is expected that the two functions are defined the same
way. In a future GHC release mappend
will be removed from Monoid
.
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #
An infix synonym for fmap
.
The name of this operator is an allusion to $
.
Note the similarities between their types:
($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b
Whereas $
is function application, <$>
is function
application lifted over a Functor
.
Examples
Convert from a
to a Maybe
Int
using Maybe
String
show
:
>>>
show <$> Nothing
Nothing>>>
show <$> Just 3
Just "3"
Convert from an
to an
Either
Int
Int
Either
Int
String
using show
:
>>>
show <$> Left 17
Left 17>>>
show <$> Right 17
Right "17"
Double each element of a list:
>>>
(*2) <$> [1,2,3]
[2,4,6]
Apply even
to the second element of a pair:
>>>
even <$> (2,2)
(2,True)
optional :: Alternative f => f a -> f (Maybe a) #
One or none.
It is useful for modelling any computation that is allowed to fail.
Examples
Using the Alternative
instance of Control.Monad.Except, the following functions:
>>>
import Control.Monad.Except
>>>
canFail = throwError "it failed" :: Except String Int
>>>
final = return 42 :: Except String Int
Can be combined by allowing the first function to fail:
>>>
runExcept $ canFail *> final
Left "it failed">>>
runExcept $ optional canFail *> final
Right 42
short :: forall (f :: Type -> Type) a. HasName f => Char -> Mod f a #
Specify a short name for an option.
value :: forall (f :: Type -> Type) a. HasValue f => a -> Mod f a #
Specify a default value for an option.
Note: Because this modifier means the parser will never fail,
do not use it with combinators such as some
or many
, as
these combinators continue until a failure occurs.
Careless use will thus result in a hang.
To display the default value, combine with showDefault or showDefaultWith.
(<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4 #
A variant of <*>
with the arguments reversed.
liftA :: Applicative f => (a -> b) -> f a -> f b #
Lift a function to actions.
Equivalent to Functor's fmap
but implemented using only Applicative
's methods:
liftA
f a = pure
f <*>
a
As such this function may be used to implement a Functor
instance from an Applicative
one.
Examples
Using the Applicative instance for Lists:
>>>
liftA (+1) [1, 2]
[2,3]
Or the Applicative instance for Maybe
>>>
liftA (+1) (Just 3)
Just 4
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d #
Lift a ternary function to actions.
asum :: (Foldable t, Alternative f) => t (f a) -> f a #
The sum of a collection of actions using (<|>)
, generalizing concat
.
asum
is just like msum
, but generalised to Alternative
.
Examples
Basic usage:
>>>
asum [Just "Hello", Nothing, Just "World"]
Just "Hello"
readerAbort :: ParseError -> ReadM a #
Abort option reader by exiting with a ParseError
.
readerError :: String -> ReadM a #
Abort option reader by exiting with an error message.
overFailure :: (ParserHelp -> ParserHelp) -> ParserResult a -> ParserResult a #
internal :: forall (f :: Type -> Type) a. Mod f a #
Hide this option completely from the help text
Use hidden
if the option should remain visible in the full description.
listCompleter :: [String] -> Completer #
Create a Completer
from a constant
list of strings.
bashCompleter :: String -> Completer #
Run a compgen completion action.
Common actions include file
and
directory
. See
http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#Programmable-Completion-Builtins
for a complete list.
eitherReader :: (String -> Either String a) -> ReadM a #
Convert a function producing an Either
into a reader.
As an example, one can create a ReadM from an attoparsec Parser easily with
import qualified Data.Attoparsec.Text as A import qualified Data.Text as T attoparsecReader :: A.Parser a -> ReadM a attoparsecReader p = eitherReader (A.parseOnly p . T.pack)
long :: forall (f :: Type -> Type) a. HasName f => String -> Mod f a #
Specify a long name for an option.
showDefaultWith :: forall a (f :: Type -> Type). (a -> String) -> Mod f a #
Specify a function to show the default value for an option.
showDefault :: forall a (f :: Type -> Type). Show a => Mod f a #
Show the default value for this option using its Show
instance.
helpDoc :: forall (f :: Type -> Type) a. Maybe Doc -> Mod f a #
Specify the help text for an option as a 'Prettyprinter.Doc AnsiStyle' value.
noArgError :: ParseError -> Mod OptionFields a #
Specify the error to display when no argument is provided to this option.
metavar :: forall (f :: Type -> Type) a. HasMetavar f => String -> Mod f a #
Specify a metavariable for the argument.
Metavariables have no effect on the actual parser, and only serve to specify the symbolic name for an argument to be displayed in the help text.
forall (f :: Type -> Type) a. Mod f a #
::Hide this option from the brief description.
Use internal
to hide the option from the help text too.
style :: forall (f :: Type -> Type) a. (Doc -> Doc) -> Mod f a #
Apply a function to the option description in the usage text.
import Options.Applicative.Help flag' () (short 't' <> style (annotate bold))
NOTE: This builder is more flexible than its name and example
allude. One of the motivating examples for its addition was to
use const
to completely replace the usage text of an option.
command :: String -> ParserInfo a -> Mod CommandFields a #
Add a command to a subparser option.
Suggested usage for multiple commands is to add them to a single subparser. e.g.
sample :: Parser Sample sample = subparser ( command "hello" (info hello (progDesc "Print greeting")) <> command "goodbye" (info goodbye (progDesc "Say goodbye")) )
commandGroup :: String -> Mod CommandFields a #
completeWith :: forall (f :: Type -> Type) a. HasCompleter f => [String] -> Mod f a #
Add a list of possible completion values.
action :: forall (f :: Type -> Type) a. HasCompleter f => String -> Mod f a #
Add a bash completion action. Common actions include file
and
directory
. See
http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#Programmable-Completion-Builtins
for a complete list.
completer :: forall (f :: Type -> Type) a. HasCompleter f => Completer -> Mod f a #
Add a completer to an argument.
A completer is a function String -> IO String which, given a partial argument, returns all possible completions for that argument.
subparser :: Mod CommandFields a -> Parser a #
Builder for a command parser. The command
modifier can be used to
specify individual commands.
By default, sub-parsers allow backtracking to their parent's options when
they are completed. To allow full mixing of parent and sub-parser options,
turn on subparserInline
; otherwise, to disable backtracking completely,
use noBacktrack
.
strArgument :: IsString s => Mod ArgumentFields s -> Parser s #
Builder for a String
argument.
Arguments
:: a | default value |
-> a | active value |
-> Mod FlagFields a | option modifier |
-> Parser a |
Builder for a flag parser.
A flag that switches from a "default value" to an "active value" when
encountered. For a simple boolean value, use switch
instead.
Note: Because this parser will never fail, it can not be used with
combinators such as some
or many
, as these combinators continue until
a failure occurs. See flag'
.
Arguments
:: a | active value |
-> Mod FlagFields a | option modifier |
-> Parser a |
Builder for a flag parser without a default value.
Same as flag
, but with no default value. In particular, this flag will
never parse successfully by itself.
It still makes sense to use it as part of a composite parser. For example
length <$> many (flag' () (short 't'))
is a parser that counts the number of "-t" arguments on the command line, alternatively
flag' True (long "on") <|> flag' False (long "off")
will require the user to enter '--on' or '--off' on the command line.
abortOption :: ParseError -> Mod OptionFields (a -> a) -> Parser (a -> a) #
An option that always fails.
When this option is encountered, the option parser immediately aborts with
the given parse error. If you simply want to output a message, use
infoOption
instead.
infoOption :: String -> Mod OptionFields (a -> a) -> Parser (a -> a) #
An option that always fails and displays a message.
strOption :: IsString s => Mod OptionFields s -> Parser s #
Builder for an option taking a String
argument.
headerDoc :: Maybe Doc -> InfoMod a #
Specify a header for this parser as a 'Prettyprinter.Doc AnsiStyle' value.
footerDoc :: Maybe Doc -> InfoMod a #
Specify a footer for this parser as a 'Prettyprinter.Doc AnsiStyle' value.
progDescDoc :: Maybe Doc -> InfoMod a #
Specify a short program description as a 'Prettyprinter.Doc AnsiStyle' value.
failureCode :: Int -> InfoMod a #
Specify an exit code if a parse error occurs.
noIntersperse :: InfoMod a #
Disable parsing of regular options after arguments. After a positional argument is parsed, all remaining options and arguments will be treated as a positional arguments. Not recommended in general as users often expect to be able to freely intersperse regular options and flags within command line options.
forwardOptions :: InfoMod a #
Intersperse matched options and arguments normally, but allow unmatched options to be treated as positional arguments. This is sometimes useful if one is wrapping a third party cli tool and needs to pass options through, while also providing a handful of their own options. Not recommended in general as typos by the user may not yield a parse error and cause confusion.
multiSuffix :: String -> PrefsMod #
Include a suffix to attach to the metavar when multiple values can be entered.
Turn on disambiguation.
See https://github.com/pcapriotti/optparse-applicative#disambiguation
Show full help text on any error.
Show the help text if the user enters only the program name or subcommand.
This will suppress a "Missing:" error and show the full usage instead if a user just types the name of the program.
noBacktrack :: PrefsMod #
Turn off backtracking after subcommand is parsed.
Allow full mixing of subcommand and parent arguments by inlining selected subparsers into the parent parser.
NOTE: When this option is used, preferences for the subparser which effect the parser behaviour (such as noIntersperse) are ignored.
Show equals sign, rather than space, in usage and help text for options with long names.
Show global help information in subparser usage.
helpIndent :: Int -> PrefsMod #
Set fill width in help text presentation.
prefs :: PrefsMod -> ParserPrefs #
Create a ParserPrefs
given a modifier
Default preferences.
A hidden "helper" option which always fails.
A common usage pattern is to apply this applicatively when
creating a ParserInfo
opts :: ParserInfo Sample opts = info (sample <**> helper) mempty
hsubparser :: Mod CommandFields a -> Parser a #
Builder for a command parser with a "helper" option attached.
Used in the same way as subparser
, but includes a "--help|-h" inside
the subcommand.
A hidden "--version" option that displays the version.
opts :: ParserInfo Sample opts = info (sample <**> simpleVersioner "v1.2.3") mempty
execParser :: ParserInfo a -> IO a #
Run a program description.
Parse command line arguments. Display help text and exit if any parse error occurs.
customExecParser :: ParserPrefs -> ParserInfo a -> IO a #
Run a program description with custom preferences.
handleParseResult :: ParserResult a -> IO a #
Handle ParserResult
.
getParseResult :: ParserResult a -> Maybe a #
Extract the actual result from a ParserResult
value.
This function returns Nothing
in case of errors. Possible error messages
or completion actions are simply discarded.
If you want to display error messages and invoke completion actions
appropriately, use handleParseResult
instead.
Arguments
:: ParserPrefs | Global preferences for this parser |
-> ParserInfo a | Description of the program to run |
-> [String] | Program arguments |
-> ParserResult a |
The most general way to run a program description in pure code.
parserFailure :: ParserPrefs -> ParserInfo a -> ParseError -> [Context] -> ParserFailure ParserHelp #
Generate a ParserFailure
from a ParseError
in a given Context
.
This function can be used, for example, to show the help text for a parser:
handleParseResult . Failure $ parserFailure pprefs pinfo (ShowHelpText Nothing) mempty
renderFailure :: ParserFailure ParserHelp -> String -> (String, ExitCode) #