[Haskell] Re: [Haskell-cafe] matching constructors

Brandon Michael Moore brandon at its.caltech.edu
Mon Mar 8 18:45:41 EST 2004


I think the generics approach really is overkill here, but it's nice to
know the generics library.

For option processing Tomasz Ziolonka described a nice technique
in the post I refered to. You can find the post in the archives at
http://www.haskell.org//pipermail/haskell/2004-January/013412.html

The big example at the end of his post seems to have exactly the otpion
structure you want, with input, output, a verbose flag, and a (composable)
selection of filters to use.

The basic idea is to make a record containing the options in their most
useful form and make each options descriptor (I assume you are using
(System.Console.)GetOpt here) return a function that transforms an option
record to reflect that option. Now to handle the list of values you get
back you just apply each transformer in turn to the default options.

It somewhat resmbles building up option values in a collection of mutable
variables, although of course values are rather more flexible in Haskell
than most other languages, and the "state" is encapsulated and well
behaved.

Brandon



More information about the Haskell mailing list