[Haskell-cafe] Parsing arguments and reading configuration
Sterling Clover
s.clover at gmail.com
Sun Sep 21 11:02:06 EDT 2008
Alternately, just go with a map initially with default values. Then
parse the command line args into a second map (especially if they're
all of a format like -argname argvalue). Then lookup your args file
with the command line map, and failing that the default map. Then
read the args file and finally merge all three maps in the proper
order. No need for monoid instances, special data types or any of
that, so at a little cost in elegance a much more succinct way to get
what you want. As a final step, you can always project the map values
into a record type, to get some safety for the rest of your program.
The entire process, aside from creating the record, should probably
be no more than four or so lines.
--Sterl.
On Sep 19, 2008, at 8:39 PM, Antoine Latter wrote:
> On Fri, Sep 19, 2008 at 7:35 PM, Antoine Latter
> <aslatter at gmail.com> wrote:
>> I'm not sure how well it would hold up under maintenance, but you
>> coud
>> have a config sum-type which is itself a monoid, and then create two
>> of them:
>>
>
> And by sum-type I mean product type. Sheesh.
>
> Although having your config options in a sum-type packed into a Set,
> which is itself a Monoid is another option. Then you get 'mempty' and
> 'mappend' for free.
>
> I think I saw a blog-post or something detailing this, but I don't
> have a book-mark.
>
> -Antoine
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list