HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleturtle-1.6.2Haskell2010

Turtle.Options

Example usage of this module:

-- options.hs

{-# LANGUAGE OverloadedStrings #-}

import Turtle

parser :: Parser (Text, Int)
parser = (,) <$> optText "name" 'n' "Your first name"
             <*> optInt  "age"  'a' "Your current age"

main = do
    (name, age) <- options "Greeting script" parser
    echo (repr (format ("Hello there, "%s) name))
    echo (repr (format ("You are "%d%" years old") age))
$ ./options --name John --age 42
Hello there, John
You are 42 years old
$ ./options --help
Greeting script

Usage: options (-n|--name NAME) (-a|--age AGE)

Available options:
 -h,--help                Show this help text
 --name NAME              Your first name
 --age AGE                Your current age

See the Turtle.Tutorial module which contains more examples on how to use command-line parsing.

  • 6 types
  • 21 values
  • Packageturtle-1.6.2
  • Exports27
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceOptions.hs

Types

6 declarations
datadata Parser a
#

A Parser a is an option parser returning a value of type a.

Instances3Functor, Applicative, Alternative
  • Functor ParserDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Types
  • Applicative ParserDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Types
  • Alternative ParserDefined in optparse-applicative-0.18.1.0 · Options.Applicative.Types
newtypenewtype ArgName
#

The name of a command-line argument

This is used to infer the long name and metavariable for the command line flag. For example, an ArgName of "name" will create a --name flag with a NAME metavariable

Constructors

Instances1IsString
newtypenewtype CommandName
#

The name of a sub-command

This is lower-cased to create a sub-command. For example, a CommandName of "Name" will parse name on the command line before parsing the remaining arguments using the command's subparser.

Instances1IsString
typetype ShortName = Char
#

The short one-character abbreviation for a flag (i.e. -n)

Flag-based option parsers

9 declarations

Positional argument parsers

8 declarations

Consume parsers

4 declarations
valueoptionsExt
  1. :: MonadIO io
  2. => Header
  3. -> Footer
  4. -> Description
  5. -> Version
  6. -> Parser a
  7. -> io a
#

Parse the given options from the command line and add additional information

Extended version of options with program version header and footer information