[mercury-users] partial instantiation?
Ondrej Bojar
bojar at ufal.mff.cuni.cz
Tue Apr 20 06:10:37 AEST 2010
Hi,
Tomas By wrote:
> I'd be interested in ideas about how to do this in Mercury. My only
> absolute requirement is that the list of commands (e.g. cmd/3) must be
> short and simple.
How about this:
:- type argtype ---> i; s.
:- type argdesc == list(pair(int, argtype)).
:- type cmd --->
run(int, string)
; do(string).
:- pred cmd(string, argdesc, cmd).
:- mode cmd(out, out, out) is multi.
:- mode cmd(in, out, out) is semidet.
cmd("hi", [[], [2-s], [1-i]], run(0, "filename")).
% you may list the different shortcut calls on separate lines
:- func interpret(list(string)) = cmd.
interpret(Args, Replacements) :-
if Args = [CmdName | CmdArgs]
then
(
if cmd(CmdName, ArgDesc, CmdDefault)
then
type_to_term(Cmd, CmdTerm),
% now replace the corresponding default values with what's given in
% CmdArgs, interpreted using ArgDesc; check for errors (user supplies
% string where int is expected..., nonexisting file given where existing
% one is expected (the good thing is that you may support more types
% on the user's side
% finish with
% try_term_to_type(ReplacedTerm, MayCmd),
% (
% MayCmd = error(E),
% ...
% ;
% MayCmd = ok(Cmd)
% )
else ...
else % no cmd given
...
Cheers, Ondrej.
>
> /Tomas
>
>
> --------------------------------------------------------------------------
> mercury-users mailing list
> Post messages to: mercury-users at csse.unimelb.edu.au
> Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
> Subscriptions: mercury-users-request at csse.unimelb.edu.au
> --------------------------------------------------------------------------
--
Ondrej Bojar (mailto:obo at cuni.cz / bojar at ufal.mff.cuni.cz)
http://www.cuni.cz/~obo
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list