[Haskell-cafe] GetOpt
Bulat Ziganshin
bulat.ziganshin at gmail.com
Thu Apr 27 10:16:20 EDT 2006
Hello Tomasz,
Thursday, April 27, 2006, 4:45:45 PM, you wrote:
> On Thu, Apr 27, 2006 at 03:10:32PM +0400, Bulat Ziganshin wrote:
>> i don't like the GetOpt interface (it returns a list of options what
>> is unusable for high-speed application)
> This got me interested. I assume that you measured performace and it
> wasn't fast enough.
no, i abandoned this without testing :)
you misunderstood me, though - i mean speed of using this list. if
some internal function need option "foo", it should scan the entire
list to find it's value. so i (like you, i think) save the result of
option parsing in the structure. and because i anyway need the way to
extract options from list and store them into structure - i
implemented my own set of functions to recognize options too.
ultimately, the main problem of all options-parsing stuff i ever seen,
is requirement to repeat option definition many times. if i have, say,
40 options, then i need to maintain 3 to 5 program fragments that deal
with each option. something like this:
data Options = Options { r :: Bool,
x :: Int
....
}
options = { "r", "description"
....
}
main = do list <- getOpts options cmdline
let options = Options { r = findBoolOption list "r",
x = findIntOption list "x",
....
}
each change in options list mean that i should find all these places
and correct them. PescoCmd may be does something against this problem,
i don't remember why i was pleased by this library
as far as i see, solving of this problem is impossible in Haskell
itself, we need some form of preprocessing, probably with TH. this
should allow us to write something like this:
$(optionProcessor [("r", "description", `Bool, .....)
,("x", .....
...
]
)
what will generate all the stuff above
as i already said, you can find module Cmdline in my program, that
is not ultimate solution, but at least it somewhat simplified my work
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe
mailing list