Page 1

Command-Line Parsing Combinators

Half-baked talk on February 11, 2005

by Thomas Hallgren

Page 2

Introduction

How to implement command line parsing

Page 3

Context

We write our programs in Haskell

Page 4

Example

Page 5

Documentation ≈ Implementation

Page 6

Implementation of the example

Page 7
Implementation of the example

...and implementations of the four commands:

cat :: [FilePath] -> IO ()
ls :: Bool -> [FilePath] -> IO ()
date :: IO ()
help :: IO ()

Page 8

Parsing combinators

Traditional, without documentation

Page 9
Parsing combinators

Modified for producing documentation

Page 10
Parsing combinators

Some derived combinators

Page 11

A note on how to parse sequences

Page 12

Traditional parsing combinators

Page 13

Simplifying assumptions for our purposes

Page 14

Implementation of our command line parsing combinators

Page 15
Implementation of our command line parsing combinators

But the above is not a valid Haskell 98 data type!

Page 16
Implementation of our command line parsing combinators

Implementation using existential data types

Page 17
Implementation of our command line parsing combinators

Given the above data type we can easily implement the desired operations on P a

Page 18

Alternative implementation of our command line parsing combinators

New combinators that return a pair of

Page 19

Other potential solutions (1)

GetOpt

An existing library for parsing command line options

Page 20

Other potential solutions (2)

Use the type class system to construct parser from types

Page 21

Conclusion

Page 22
Conclusion

TODO

Page 23

The end

Questions?