getOpt return record of type a rather than [a]

Lemmih lemmih at gmail.com
Tue Dec 18 17:22:43 EST 2007


On Dec 18, 2007 11:10 PM, Henning Thielemann
<lemming at henning-thielemann.de> wrote:
>
> 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"
>
>
>
> I feel this approach is so natural, that someone must have implemented it
> already.

Indeed, we to this in HAppS, for instance. Folding the resulting list
makes the current GetOpt implementation more than adequate.

-- 
Cheers,
  Lemmih


More information about the Libraries mailing list