simpleOptions :: Stringversion string
-> Stringheader
-> Stringprogram description
-> Parser aglobal settings
-> ExceptT b (Writer (Mod CommandFields b)) ()commands (use addCommand)
-> IO (a, b)
Generate and execute a simple options parser.
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27
Moduleoptparse-simple-0.1.1.4Haskell2010
Simple interface to program arguments.
Typical usage with no commands:
do (opts,()) <-
simpleOptions "ver"
"header"
"desc"
(flag () () (long "some-flag"))
empty
doThings opts
Typical usage with commands:
do (opts,runCmd) <-
simpleOptions "ver"
"header"
"desc"
(pure ()) $
do addCommand "delete"
"Delete the thing"
(const deleteTheThing)
(pure ())
addCommand "create"
"Create a thing"
createAThing
(strOption (long "hello"))
runCmd
simpleOptions :: Stringversion string
-> Stringheader
-> Stringprogram description
-> Parser aglobal settings
-> ExceptT b (Writer (Mod CommandFields b)) ()commands (use addCommand)
-> IO (a, b)Generate and execute a simple options parser.
simpleParser :: Parser acommon settings
-> ExceptT b (Writer (Mod CommandFields b)) ()commands (use addCommand)
-> Parser (a, b)Generate a simple options parser.
Most of the time you should use simpleOptions instead, but simpleParser can be used for sub-commands that need common options. For example:
addCommand "thing"
"Subcommands that operate on things"
(\(opts,runSubCmd) -> runSubCmd opts)
(simpleParser (flag () () (long "some-flag")) $
do addCommand "delete"
"Delete the thing"
(const deleteTheThing)
(pure ())
addCommand "create"
"Create a thing"
createAThing
(strOption (long "hello")))
Generate a string like Version 1.2, Git revision 1234.
$(simpleVersion …) :: String
addCommand Add a command to the options dispatcher.
addSubCommands :: Stringcommand string
-> Stringtitle of command
-> ExceptT b (Writer (Mod CommandFields b)) ()sub-commands (use addCommand)
-> ExceptT b (Writer (Mod CommandFields b)) ()Add a command that takes sub-commands to the options dispatcher.
Example:
addSubCommands "thing"
"Subcommands that operate on things"
(do addCommand "delete"
"Delete the thing"
(const deleteTheThing)
(pure ())
addCommand "create"
"Create a thing"
createAThing
(strOption (long "hello")))
If there are common options between all the sub-commands, use addCommand in combination with simpleParser instead of addSubCommands.
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 idliftA2 f x y = f Prelude.<$> x <*> yFurther, any definition must satisfy the following:
pure id <*> v = vpure (.) <*> u <*> v <*> w = u <*> (v <*> w)pure f <*> pure x = pure (f x)u <*> pure y = pure ($ y) <*> uThe 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 yit follows from the above that
liftA2 p (liftA2 q u v) = liftA2 f u . liftA2 g vIf f is also a Monad, it should satisfy
(which implies that pure and <*> satisfy the applicative functor laws).
pure :: a -> f aLift a value into the Structure.
pure 1 :: Maybe IntJust 1
pure 'z' :: [Char]"z"
pure (pure ":D") :: Maybe [String]Just [":D"]
(<*>) :: f (a -> b) -> f a -> f binfixl 4Sequential application.
A few functors support an implementation of <*> that is more efficient than the default one.
Used in combination with , (Data.Functor.<$>) can be used to build a record.(<*>)
data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}produceFoo :: Applicative f => f FooproduceBar :: Applicative f => f BarproduceBaz :: Applicative f => f Baz
mkState :: Applicative f => f MyStatemkState = MyState <$> produceFoo <*> produceBar <*> produceBaz
liftA2 :: (a -> b -> c) -> f a -> f b -> f cLift 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.
liftA2 (,) (Just 3) (Just 5)Just (3,5)
liftA2 (+) [1, 2, 3] [4, 5, 6][5,6,7,6,7,8,7,8,9]
(*>) :: f a -> f b -> f binfixl 4Sequence actions, discarding the value of the first argument.
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 3Just 3
Nothing *> Just 3Nothing
Of course a more interesting use case would be to have effectful computations instead of just returning pure values.
import Data.Charimport GHC.Internal.Text.ParserCombinators.ReadPlet p = string "my name is " *> munch1 isAlpha <* eofreadP_to_S p "my name is Simon"[("Simon","")]
(<*) :: f a -> f b -> f ainfixl 4Sequence actions, discarding the value of the second argument.
Applicative ComplexDefined in base-4.20.2.0 · Data.ComplexApplicative FirstDefined in base-4.20.2.0 · Data.SemigroupApplicative LastDefined in base-4.20.2.0 · Data.SemigroupApplicative MaxDefined in base-4.20.2.0 · Data.SemigroupApplicative MinDefined in base-4.20.2.0 · Data.SemigroupApplicative GetDefined in binary-0.8.9.3 · Data.Binary.Get.InternalApplicative PutMDefined in binary-0.8.9.3 · Data.Binary.PutApplicative PutDefined in bytestring-0.12.2.0 · Data.ByteString.Builder.InternalApplicative RGBDefined in colour-2.3.6 · Data.Colour.RGBApplicative SeqDefined in containers-0.7 · Data.Sequence.InternalApplicative TreeDefined in containers-0.7 · Data.TreeApplicative NonEmptyDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseApplicative STMDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.SyncApplicative IdentityDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityApplicative FirstDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.MonoidApplicative LastDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.MonoidApplicative DownDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.OrdApplicative DualDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalApplicative ProductDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalApplicative SumDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalApplicative ZipListDefined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListf <$> ZipList xs1 <*> ... <*> ZipList xsN
= ZipList (zipWithN f xs1 ... xsN)where zipWithN refers to the zipWith function of the appropriate arity
(zipWith, zipWith3, zipWith4, ...). For example:
(\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"]}Applicative NoIODefined in ghc-internal-9.1003.0 · GHC.Internal.GHCiApplicative Par1Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsApplicative MaybeDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseApplicative PDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPApplicative ReadPDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPApplicative ReadPrecDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPrecApplicative SoloDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseApplicative IODefined in ghc-internal-9.1003.0 · GHC.Internal.BaseApplicative ChunkDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Help.ChunkApplicative ComplResultDefined in optparse-applicative-0.18.1.0 · Options.Applicative.InternalApplicative CompletionDefined in optparse-applicative-0.18.1.0 · Options.Applicative.InternalApplicative PDefined in optparse-applicative-0.18.1.0 · Options.Applicative.InternalApplicative ParserDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesApplicative ParserMDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesApplicative ParserResultDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesApplicative ReadMDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesApplicative STMDefined in stm-2.5.3.1 · Control.Sequential.STMApplicative PprMDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.PprLibApplicative QDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxApplicative []Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseApplicative ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyApplicative U1Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsApplicative (SetM s)Defined in containers-0.7 · Data.GraphApplicative (State s)Defined in containers-0.7 · Utils.Containers.Internal.StateApplicative (ST s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.ST.Lazy.ImpApplicative (Either e)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.EitherApplicative (StateL s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.UtilsApplicative (StateR s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.UtilsApplicative (ST s)Defined in ghc-internal-9.1003.0 · GHC.Internal.STApplicative (UniqueParser s)Defined in prettyprinter-1.7.1 · Prettyprinter.Render.Util.SimpleDocTreeApplicative (IParser t)Defined in text-2.1.3 · Data.Text.Internal.ReadApplicative f => Applicative (Lift f)Defined in transformers-0.6.1.1 · Control.Applicative.LiftA combination is Pure only if both parts are.
Applicative m => Applicative (QuoteToQuasi m)Defined in th-compat-0.1.6 · Language.Haskell.TH.Syntax.CompatMonad m => Applicative (WrappedMonad m)Defined in base-4.20.2.0 · Control.ApplicativeMonad m => Applicative (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonad m => Applicative (ListT m)Defined in optparse-applicative-0.18.1.0 · Options.Applicative.InternalMonad m => Applicative (NondetT m)Defined in optparse-applicative-0.18.1.0 · Options.Applicative.InternalMonoid a => Applicative (Tuple2 a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseArrow a => Applicative (ArrowMonad a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow(Functor m, Monad m) => Applicative (MaybeT m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.MaybeApplicative (t m) => Applicative (LiftingAccum t m)Defined in mtl-2.3.1 · Control.Monad.AccumApplicative (t m) => Applicative (LiftingSelect t m)Defined in mtl-2.3.1 · Control.Monad.SelectApplicative f => Applicative (Ap f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.MonoidApplicative f => Applicative (Alt f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalApplicative f => Applicative (Rec1 f)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsApplicative f => Applicative (Backwards f)Defined in transformers-0.6.1.1 · Control.Applicative.BackwardsApply f-actions in the reverse order.
Applicative f => Applicative (Reverse f)Defined in transformers-0.6.1.1 · Data.Functor.ReverseDerived instance.
Applicative m => Applicative (Kleisli m a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.ArrowApplicative m => Applicative (IdentityT m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.IdentityApplicative m => Applicative (ReaderT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ReaderMonad m => Applicative (StateT s m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.UtilsMonoid a => Applicative (Constant a)Defined in transformers-0.6.1.1 · Data.Functor.ConstantMonoid m => Applicative (Const m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstMonoid output => Applicative (StackMachine output style)Defined in prettyprinter-1.7.1 · Prettyprinter.Render.Util.StackMachineArrow a => Applicative (WrappedArrow a b)Defined in base-4.20.2.0 · Control.Applicative(Applicative f, Monad f) => Applicative (WhenMissing f x)Defined in containers-0.7 · Data.IntMap.InternalEquivalent to ReaderT k (ReaderT x (MaybeT f)).
(Functor m, Monad m) => Applicative (ExceptT e m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Except(Functor m, Monad m) => Applicative (SelectT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Select(Functor m, Monad m) => Applicative (StateT s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.Lazy(Functor m, Monad m) => Applicative (StateT s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.Strict(Functor m, Monad m) => Applicative (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPS(Monoid a, Monoid b) => Applicative (Tuple3 a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base(Monoid w, Applicative m) => Applicative (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Monoid w, Applicative m) => Applicative (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Strict(Monoid w, Functor m, Monad m) => Applicative (AccumT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Accum(Generic1 f, Applicative (Rep1 f)) => Applicative (Generically1 f)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsApplicative (ContT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ContApplicative ((->) r)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseMonoid c => Applicative (K1 i c)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Applicative f, Applicative g) => Applicative (Product f g)Defined in base-4.20.2.0 · Data.Functor.Product(Applicative f, Applicative g) => Applicative (f :*: g)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Applicative f, Monad f) => Applicative (WhenMissing f k x)Defined in containers-0.7 · Data.Map.InternalEquivalent to ReaderT k (ReaderT x (MaybeT f)) .
(Monad f, Applicative f) => Applicative (WhenMatched f x y)Defined in containers-0.7 · Data.IntMap.InternalEquivalent to ReaderT Key (ReaderT x (ReaderT y (MaybeT f)))
(Monoid a, Monoid b, Monoid c) => Applicative (Tuple4 a b c)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseApplicative f => Applicative (M1 i c f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Applicative f, Applicative g) => Applicative (Compose f g)Defined in base-4.20.2.0 · Data.Functor.Compose(Applicative f, Applicative g) => Applicative (f :.: g)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Functor m, Monad m) => Applicative (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.CPS(Monad f, Applicative f) => Applicative (WhenMatched f k x y)Defined in containers-0.7 · Data.Map.InternalEquivalent to ReaderT k (ReaderT x (ReaderT y (MaybeT f)))
(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.Lazy(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.StrictA Parser a is an option parser returning a value of type a.
Functor ParserDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesApplicative ParserDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesAlternative ParserDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesAn 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 by f.
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 Options.Applicative.Builder).
HasMetavar CommandFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalexecParserPure :: ParserPrefsGlobal preferences for this parser
-> ParserInfo aDescription of the program to run
-> [String]Program arguments
-> ParserResult aThe most general way to run a program description in pure code.
Create a ParserPrefs given a modifier
Trivial option modifier.
Result of execParserPure.
Monad ParserResultDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesFunctor ParserResultDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesApplicative ParserResultDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesShow a => Show (ParserResult a)Defined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesRun a program description.
Parse command line arguments. Display help text and exit if any parse error occurs.
Handle ParserResult.
Create a ParserInfo given a Parser and a modifier.
Show a full description in the help text of this parser (default).
Specify a header for this parser.
Specify a short program description.
An option that always fails and displays a message.
Specify a long name for an option.
Specify the help text for an option.
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"))
)
An infix synonym for fmap.
The name of this operator is an allusion to Prelude.$.
Note the similarities between their types:
($) :: (a -> b) -> a -> b
(<$>) :: Functor f => (a -> b) -> f a -> f bWhereas Prelude.$ is function application, <$> is function
application lifted over a Functor.
Convert from a Maybe Int to a Maybe
String using show:
show <$> NothingNothing
show <$> Just 3Just "3"
Convert from an Either Int Int to an
Either Int String using show:
show <$> Left 17Left 17
show <$> Right 17Right "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)
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) memptyAn 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.
Semigroup ParseErrorDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesMonoid ParseErrorDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesBuilder 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.
Replace all locations in the input with the same value.
The default definition is fmap . const, but this may be
overridden with a more efficient version.
Perform a computation with Maybe and replace the result with a constant value if it is Just:
'a' <$ Just 2Just 'a''a' <$ NothingNothing
An associative operation
NOTE: This method is redundant and has the default
implementation mappend = (<>) since base-4.11.0.0.
Should it be implemented manually, since 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.
A monoid on applicative functors.
If defined, some and many should be the least solutions of the equations:
Nothing <|> Just 42Just 42
[1, 2] <|> [3, 4][1,2,3,4]
empty <|> print (2^15)32768
empty :: f aThe identity of <|>
empty <|> a == a
a <|> empty == a(<|>) :: f a -> f a -> f ainfixl 3An associative binary operation
some :: f a -> f [a]One or more.
some (putStr "la")lalalalalalalalala... * goes on forever *
some Nothingnothing
take 5 <$> some (Just 1)* hangs forever *
Note that this function can be used with Parsers based on
Applicatives. In that case some parser will attempt to
parse parser one or more times until it fails.
many :: f a -> f [a]Zero or more.
many (putStr "la")lalalalalalalalala... * goes on forever *
many NothingJust []
take 5 <$> many (Just 1)* hangs forever *
Note that this function can be used with Parsers based on
Applicatives. In that case many parser will attempt to
parse parser zero or more times until it fails.
Alternative GetDefined in binary-0.8.9.3 · Data.Binary.Get.InternalAlternative SeqDefined in containers-0.7 · Data.Sequence.InternalAlternative STMDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.SyncAlternative ZipListDefined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListAlternative MaybeDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseAlternative PDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPAlternative ReadPDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPAlternative ReadPrecDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPrecAlternative IODefined in ghc-internal-9.1003.0 · GHC.Internal.BaseAlternative ChunkDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Help.ChunkAlternative CompletionDefined in optparse-applicative-0.18.1.0 · Options.Applicative.InternalAlternative PDefined in optparse-applicative-0.18.1.0 · Options.Applicative.InternalAlternative ParserDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesAlternative ReadMDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesAlternative []Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseCombines lists by concatenation, starting from the empty list.
Alternative ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyAlternative U1Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsAlternative (UniqueParser s)Defined in prettyprinter-1.7.1 · Prettyprinter.Render.Util.SimpleDocTreeAlternative f => Alternative (Lift f)Defined in transformers-0.6.1.1 · Control.Applicative.LiftA combination is Pure only either part is.
Monad m => Alternative (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonad m => Alternative (ListT m)Defined in optparse-applicative-0.18.1.0 · Options.Applicative.InternalMonad m => Alternative (NondetT m)Defined in optparse-applicative-0.18.1.0 · Options.Applicative.InternalMonadPlus m => Alternative (WrappedMonad m)Defined in base-4.20.2.0 · Control.ApplicativeArrowPlus a => Alternative (ArrowMonad a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow(Functor m, Monad m) => Alternative (MaybeT m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.MaybeAlternative f => Alternative (Ap f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.MonoidAlternative f => Alternative (Alt f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalAlternative f => Alternative (Rec1 f)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsAlternative f => Alternative (Backwards f)Defined in transformers-0.6.1.1 · Control.Applicative.BackwardsTry alternatives in the same order as f.
Alternative f => Alternative (Reverse f)Defined in transformers-0.6.1.1 · Data.Functor.ReverseDerived instance.
Alternative m => Alternative (Kleisli m a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.ArrowAlternative m => Alternative (IdentityT m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.IdentityAlternative m => Alternative (ReaderT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Reader(Functor m, Monad m, Monoid e) => Alternative (ExceptT e m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Except(Functor m, MonadPlus m) => Alternative (SelectT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Select(Functor m, MonadPlus m) => Alternative (StateT s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.Lazy(Functor m, MonadPlus m) => Alternative (StateT s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.Strict(Functor m, MonadPlus m) => Alternative (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPS(Monoid w, Alternative m) => Alternative (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Monoid w, Alternative m) => Alternative (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Strict(Monoid w, Functor m, MonadPlus m) => Alternative (AccumT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Accum(ArrowZero a, ArrowPlus a) => Alternative (WrappedArrow a b)Defined in base-4.20.2.0 · Control.Applicative(Generic1 f, Alternative (Rep1 f)) => Alternative (Generically1 f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Alternative f, Alternative g) => Alternative (Product f g)Defined in base-4.20.2.0 · Data.Functor.Product(Alternative f, Alternative g) => Alternative (f :*: g)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsAlternative f => Alternative (M1 i c f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Alternative f, Applicative g) => Alternative (Compose f g)Defined in base-4.20.2.0 · Data.Functor.Compose(Alternative f, Applicative g) => Alternative (f :.: g)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Functor m, MonadPlus m) => Alternative (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.CPS(Monoid w, Functor m, MonadPlus m) => Alternative (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.Lazy(Monoid w, Functor m, MonadPlus m) => Alternative (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.StrictA variant of <*> with the types of the arguments reversed. It differs from
flip in that the effects are resolved in the order the arguments are
presented.(<*>)
(<**>) (print 1) (id <$ print 2)12
flip (<*>) (print 1) (id <$ print 2)21
ZipList [4, 5, 6] <**> ZipList [(+1), (*2), (/3)]ZipList {getZipList = [5.0,10.0,2.0]}
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.
Using the Applicative instance for Lists:
liftA (+1) [1, 2][2,3]
Or the Applicative instance for Maybe
liftA (+1) (Just 3)Just 4
Lift a ternary function to actions.
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'.
The Const functor.
fmap (++ "World") (Const "Hello")Const "Hello"
Because we ignore the second type parameter to Const,
the Applicative instance, which has
essentially turns into (<*>) :: Monoid m => Const m (a -> b) -> Const m a -> Const m bMonoid m => m -> m -> m, which is (<>)
Const [1, 2, 3] <*> Const [4, 5, 6]Const [1,2,3,4,5,6]
Generic1 (Const a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstBifoldable ConstDefined in base-4.20.2.0 · Data.BifoldableBifoldable1 ConstDefined in base-4.20.2.0 · Data.Bifoldable1Bifunctor ConstDefined in base-4.20.2.0 · Data.BifunctorBitraversable ConstDefined in base-4.20.2.0 · Data.BitraversableEq2 ConstDefined in base-4.20.2.0 · Data.Functor.ClassesOrd2 ConstDefined in base-4.20.2.0 · Data.Functor.ClassesRead2 ConstDefined in base-4.20.2.0 · Data.Functor.ClassesShow2 ConstDefined in base-4.20.2.0 · Data.Functor.ClassesNFData2 ConstDefined in deepseq-1.5.0.0 · Control.DeepSeqFunctor (Const m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstMonoid m => Applicative (Const m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstFoldable (Const m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstTraversable (Const m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.TraversableEq a => Eq1 (Const a)Defined in base-4.20.2.0 · Data.Functor.ClassesOrd a => Ord1 (Const a)Defined in base-4.20.2.0 · Data.Functor.ClassesRead a => Read1 (Const a)Defined in base-4.20.2.0 · Data.Functor.ClassesShow a => Show1 (Const a)Defined in base-4.20.2.0 · Data.Functor.ClassesContravariant (Const a)Defined in base-4.20.2.0 · Data.Functor.ContravariantNFData a => NFData1 (Const a)Defined in deepseq-1.5.0.0 · Control.DeepSeqBounded a => Bounded (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstEnum a => Enum (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstEq a => Eq (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstFloating a => Floating (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstFractional a => Fractional (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstIntegral a => Integral (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Const(Typeable k, Data a, Typeable b) => Data (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum a => Num (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstOrd a => Ord (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstRead a => Read (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstReal a => Real (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstRealFloat a => RealFloat (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstRealFrac a => RealFrac (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstShow a => Show (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstIx a => Ix (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstIsString a => IsString (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.StringGeneric (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstSemigroup a => Semigroup (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstMonoid a => Monoid (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstBits a => Bits (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstFiniteBits a => FiniteBits (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstStorable a => Storable (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstNFData a => NFData (Const a b)Defined in deepseq-1.5.0.0 · Control.DeepSeqPretty a => Pretty (Const a b)Defined in prettyprinter-1.7.1 · Prettyprinter.Internaltype Rep (Const a b) = D1 ('MetaData "Const"
"GHC.Internal.Data.Functor.Const"
"ghc-internal"
'True) (C1 ('MetaCons "Const"
'PrefixI 'True) (S1 ('MetaSel ('Just "getConst"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Consttype Rep1 (Const a) = D1 ('MetaData "Const"
"GHC.Internal.Data.Functor.Const"
"ghc-internal"
'True) (C1 ('MetaCons "Const"
'PrefixI 'True) (S1 ('MetaSel ('Just "getConst"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstSpecify 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.
Modifier for ParserInfo.
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.
Builder for an argument parser.
Only show a brief description in the help text of this parser.
Set the maximum width of the generated help text.
Add a list of possible completion values.
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.
Default preferences.
Null Option reader. All arguments will fail validation.
Turn on disambiguation.
See https://github.com/pcapriotti/optparse-applicative#disambiguation
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)Specify an exit code if a parse error occurs.
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.
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.
Specify a header for this parser as a 'Prettyprinter.Doc AnsiStyle' value.
Specify the help text for an option as a 'Prettyprinter.Doc AnsiStyle' value.
Set fill width in help text presentation.
Show equals sign, rather than space, in usage and help text for options with long names.
Show global help information in subparser usage.
Convert a function producing a Maybe into a reader.
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.
Include a suffix to attach to the metavar when multiple values can be entered.
Specify the error to display when no argument is provided to this option.
Turn off backtracking after subcommand is parsed.
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.
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' )Specify a short program description as a 'Prettyprinter.Doc AnsiStyle' value.
Specify a short name for an option.
Show the default value for this option using its Show instance.
Specify a function to show the default value for an option.
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.
Show full help text on any error.
Builder for a String argument.
Builder for an option taking a String argument.
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.
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.
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.
Create a Completer from a constant list of strings.
Create a Completer from an IO action
HasCompleter ArgumentFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasMetavar ArgumentFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasValue ArgumentFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasName FlagFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasCompleter ArgumentFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasCompleter OptionFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasMetavar ArgumentFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasMetavar CommandFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasMetavar OptionFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasName FlagFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasName OptionFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasValue ArgumentFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasValue OptionFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasCompleter OptionFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasMetavar OptionFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasName OptionFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHasValue OptionFieldsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Builder.InternalHide this option completely from the help text
Use hidden if the option should remain visible in the full description.
Run a program description with custom preferences.
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.
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.
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) memptyA hidden "--version" option that displays the version.
opts :: ParserInfo Sample
opts = info (sample <**> simpleVersioner "v1.2.3") memptyShow ParserHelpDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Help.TypesSemigroup ParserHelpDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Help.TypesMonoid ParserHelpDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Help.TypesA shell complete function.
Show CompletionResultDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesParserFailureexecFailure :: String -> (h, ExitCode, Int)Functor ParserFailureDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesShow h => Show (ParserFailure h)Defined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesA full description for a runnable Parser for a program.
ParserInfoinfoParser :: Parser athe option parser for the program
infoFullDesc :: Boolwhether the help text should contain full documentation
infoProgDesc :: Chunk Docbrief parser description
infoHeader :: Chunk Docheader of the full parser description
infoFailureCode :: Intexit code for a parser failure
infoPolicy :: ArgPolicyallow regular options and flags to occur after arguments (default: InterspersePolicy)
Functor ParserInfoDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesGlobal preferences for a top-level Parser.
ParserPrefsprefMultiSuffix :: Stringmetavar suffix for multiple options
prefDisambiguate :: Boolautomatically disambiguate abbreviations (default: False)
prefShowHelpOnError :: Boolalways show help text on parse errors (default: False)
prefShowHelpOnEmpty :: Boolshow the help text for a command or subcommand if it fails with no input (default: False)
prefBacktrack :: Backtrackingbacktrack to parent parser when a subcommand fails (default: Backtrack)
prefColumns :: Intnumber of columns in the terminal, used to format the help page (default: 80)
prefHelpLongEquals :: Boolwhen displaying long names in usage and help,
use an = sign for long names, rather than a
single space (default: False)
prefHelpShowGlobal :: Boolwhen displaying subparsers' usage help, show parent options under a "global options" section (default: False)
prefTabulateFill :: IntIndentation width for tables
Eq ParserPrefsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesShow ParserPrefsDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesA newtype over 'ReaderT String Except', used by option readers.
Monad ReadMDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesFunctor ReadMDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesMonadFail ReadMDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesApplicative ReadMDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesAlternative ReadMDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesMonadPlus ReadMDefined in optparse-applicative-0.18.1.0 · Options.Applicative.TypesSmart constructor for a Completer
Abort option reader by exiting with a ParseError.
Abort option reader by exiting with an error message.
One or none.
It is useful for modelling any computation that is allowed to fail.
Using the Alternative instance of Control.Monad.Except, the following functions:
import Control.Monad.ExceptcanFail = throwError "it failed" :: Except String Intfinal = return 42 :: Except String Int
Can be combined by allowing the first function to fail:
runExcept $ canFail *> finalLeft "it failed"
runExcept $ optional canFail *> finalRight 42
The sum of a collection of actions using (<|>), generalizing concat.
asum is just like msum, but generalised to Alternative.
Basic usage:
asum [Just "Hello", Nothing, Just "World"]Just "Hello"
WrapArrowunwrapArrow :: a b cGeneric1 (WrappedArrow a b)Defined in base-4.20.2.0 · Control.ApplicativeArrow a => Functor (WrappedArrow a b)Defined in base-4.20.2.0 · Control.ApplicativeArrow a => Applicative (WrappedArrow a b)Defined in base-4.20.2.0 · Control.Applicative(ArrowZero a, ArrowPlus a) => Alternative (WrappedArrow a b)Defined in base-4.20.2.0 · Control.Applicative(Typeable a, Typeable b, Typeable c, Data (a b c)) => Data (WrappedArrow a b c)Defined in base-4.20.2.0 · Control.ApplicativeGeneric (WrappedArrow a b c)Defined in base-4.20.2.0 · Control.Applicativetype 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))))Defined in base-4.20.2.0 · Control.Applicativetype Rep1 (WrappedArrow a b) = D1 ('MetaData "WrappedArrow"
"Control.Applicative"
"base"
'True) (C1 ('MetaCons "WrapArrow"
'PrefixI 'True) (S1 ('MetaSel ('Just "unwrapArrow"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 (a b))))Defined in base-4.20.2.0 · Control.ApplicativeWrapMonadunwrapMonad :: m aGeneric1 (WrappedMonad m)Defined in base-4.20.2.0 · Control.ApplicativeMonad m => Monad (WrappedMonad m)Defined in base-4.20.2.0 · Control.ApplicativeMonad m => Functor (WrappedMonad m)Defined in base-4.20.2.0 · Control.ApplicativeMonad m => Applicative (WrappedMonad m)Defined in base-4.20.2.0 · Control.ApplicativeMonadPlus m => Alternative (WrappedMonad m)Defined in base-4.20.2.0 · Control.Applicative(Typeable m, Typeable a, Data (m a)) => Data (WrappedMonad m a)Defined in base-4.20.2.0 · Control.ApplicativeGeneric (WrappedMonad m a)Defined in base-4.20.2.0 · Control.Applicativetype Rep (WrappedMonad m a) = D1 ('MetaData "WrappedMonad"
"Control.Applicative"
"base"
'True) (C1 ('MetaCons "WrapMonad"
'PrefixI 'True) (S1 ('MetaSel ('Just "unwrapMonad"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m a))))Defined in base-4.20.2.0 · Control.Applicativetype Rep1 (WrappedMonad m) = D1 ('MetaData "WrappedMonad"
"Control.Applicative"
"base"
'True) (C1 ('MetaCons "WrapMonad"
'PrefixI 'True) (S1 ('MetaSel ('Just "unwrapMonad"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 m)))Defined in base-4.20.2.0 · Control.ApplicativeLists, but with an Applicative functor based on zipping.
In contrast to the Applicative for GHC.List.List:
(+) <$> [1, 2, 3] <*> [4, 5, 6][5,6,7,6,7,8,7,8,9]
The Applicative instance of ZipList applies the operation by pairing up the elements, analogous to zipWithN
(+) <$> ZipList [1, 2, 3] <*> ZipList [4, 5, 6]ZipList {getZipList = [5,7,9]}
(,,,) <$> ZipList [1, 2] <*> ZipList [3, 4] <*> ZipList [5, 6] <*> ZipList [7, 8]ZipList {getZipList = [(1,3,5,7),(2,4,6,8)]}
ZipList [(+1), (^2), (/ 2)] <*> ZipList [5, 5, 5]ZipList {getZipList = [6.0,25.0,2.5]}
ZipListgetZipList :: [a]Functor ZipListDefined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListApplicative ZipListDefined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListf <$> ZipList xs1 <*> ... <*> ZipList xsN
= ZipList (zipWithN f xs1 ... xsN)where zipWithN refers to the zipWith function of the appropriate arity
(zipWith, zipWith3, zipWith4, ...). For example:
(\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"]}Foldable ZipListDefined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListTraversable ZipListDefined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListAlternative ZipListDefined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListNFData1 ZipListDefined in deepseq-1.5.0.0 · Control.DeepSeqGeneric1 ZipListDefined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListIsList (ZipList a)Defined in ghc-internal-9.1003.0 · GHC.Internal.IsListEq a => Eq (ZipList a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListData a => Data (ZipList a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListOrd a => Ord (ZipList a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListRead a => Read (ZipList a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListShow a => Show (ZipList a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListGeneric (ZipList a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListNFData a => NFData (ZipList a)Defined in deepseq-1.5.0.0 · Control.DeepSeqtype Rep (ZipList a) = D1 ('MetaData "ZipList"
"GHC.Internal.Functor.ZipList"
"ghc-internal"
'True) (C1 ('MetaCons "ZipList"
'PrefixI 'True) (S1 ('MetaSel ('Just "getZipList"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a])))Defined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListtype Rep1 ZipList = D1 ('MetaData "ZipList"
"GHC.Internal.Functor.ZipList"
"ghc-internal"
'True) (C1 ('MetaCons "ZipList"
'PrefixI 'True) (S1 ('MetaSel ('Just "getZipList"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 [])))Defined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListtype Item (ZipList a) = aDefined in ghc-internal-9.1003.0 · GHC.Internal.IsList