1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
4 <maintainer type="project">
5 <email>haskell@gentoo.org</email>
6 <name>Gentoo Haskell</name>
9 ReadArgs provides the @readArgs@ IO action, which lets you tell the compiler
10 to parse the command line arguments to fit the type signature you give.
12 For example @(a :: Int, b :: String, c :: Float) <- readArgs@ would
13 parse the first runtime argument as an @Int@, the second as a @String@ (no
14 quotes required) and the third as a @Float@.
16 If the runtime arguments are incompatible with the type signature,
17 then a simple usage statement is given of the types needed.
19 Continuing the previous example, if it was used in a
20 program named @Example@, the error message for the above
24 usage: Example Int String Float
27 Any type that has both @Typeable@ and @Read@ instances
28 can be used. @Char@, @String@, and @Text@ are handled specially so that
29 command line arguments for both do not require quotes (as their
30 @Read@ instances do). A special instance is provided for @FilePath@ so
31 that no constructor or quotes are required.
33 @readArgs@ also supports optional arguments and variadic arguments.
34 Optional arguments are specified using @Maybe@, and variadic arguments
35 using a list. @(a :: Int, b :: Maybe String, c :: [Float]) <- readArgs@
36 would successfully parse any of the following sets of command line arguments:
53 Usage statements for optional and variadic arguments use command-line
57 usage: Example Int [String] [Float..]
60 Note that both optional and variadic parsers are greedy by default
61 (so @Example 1 2 3 4@ was parsed as @(1, "2", [3.0,4.0])@. They
62 may both be made non-greedy through use of the @NonGreedy@ constructor:
66 , NonGreedy b :: NonGreedy Maybe String
67 , NonGreedy c :: NonGreedy [] Float
72 <remote-id type="github">rampion/ReadArgs</remote-id>