[darcs-devel] darcs patch: fix darcs --commands, which was broken by subcommand c...

David Roundy droundy at abridgegame.org
Sun Jul 31 05:23:49 PDT 2005


On Sat, Jul 30, 2005 at 11:55:12AM -0500, Taral wrote:
> On 7/30/05, David Roundy <droundy at abridgegame.org> wrote:
> > Perhaps we should avoid using this sort of record selector? :( I really
> > don't like the idea that we'd have to audit the entire code to find bugs
> > like this, when the compiler *ought* to be able to do it for me.
> 
> This kind of record selector really circumvents the type system, and
> ghc assumes you know what you're doing when you use it. If you want
> the compiler to notice "errors", you'll have to create types for each
> record, then build the selectors yourself. Then it'll whine when you
> mess it up.

Yuck.  They were great when we had just a single constructor for
DarcsCommand, but now it's looking quite ugly.  :(

Since commands are pretty much only *accessed* within DarcsCommands itself,
we ought to be able to use some sort of hack that will only affect that
module.  I really like the reability of having named fields in the record,
and wouldn't want to give that up.  Is there a way we could allow other
modules to import the named fields, but not to use them as accessor
functions? I'd like to be able to continue writing code like:

add = DarcsCommand {command_name = "add",
                    command_help = add_help,
                    command_get_arg_possibilities = list_unregistered_files,
                    ...
                   }

but prevent other modules from using code like

command_help add

to access the help field.  Actually, I'd like to allow command_help (which
works with all constructors of DarcsCommands, but disallow the use of

command_get_arg_possibilities add

in modules other than DarcsCommand itself.  It seems that removing
command_get_arg_possibilities from the export list means that we can't use
it as a named field in the constructor, which is a pain, since DarcsCommand
has so many fields that using their order to determine their meaning would
be well nigh unreadable.  :( Am I stuck in a corner here?
-- 
David Roundy
http://www.darcs.net




More information about the darcs-devel mailing list