18 Dec 23:09
getOpt return record of type a rather than [a]
From: Henning Thielemann <lemming <at> henning-thielemann.de>
Subject: getOpt return record of type a rather than [a]
Newsgroups: gmane.comp.lang.haskell.libraries
Date: 2007-12-18 22:10:58 GMT
Subject: getOpt return record of type a rather than [a]
Newsgroups: gmane.comp.lang.haskell.libraries
Date: 2007-12-18 22:10:58 GMT
The current version of System.Console.GetOpt.getOpt returns a list of
values, where the element type has usually one constructor per option.
data Flag
= Verbose | Version
| Input String | Output String | LibDir String
What I more like to receive is a record consisting of one constructor and
many fields, where optional options are of type Maybe, options with
multiple occurrence are of type list.
data Flag = Flag {
verbose :: Bool,
version :: Bool,
input :: Maybe FilePath,
output :: Maybe FilePath,
libdir :: FilePath
}
Then we would need
data ArgDescr a =
NoArg (a -> a)
ReqArg (String -> a -> a) String
OptArg (String -> a -> a) String
e.g.
OptArg (\path flags -> flags {input = Just path}) "FILE"
(Continue reading)
RSS Feed