[mercury-users] partial instantiation?

Ralph Becket rafe at csse.unimelb.edu.au
Mon Apr 19 11:13:53 AEST 2010


Tomas, Wednesday, 14 April 2010:
> Hi all,
> 
> I have a little program that I want to accept optional command line
> parameters, so that, for example:
> 
> $ ./binary command
> $ ./binary command filename
> $ ./binary command 100
> $ ./binary command filename 100
> 
> would all map to `command' (which is implemented by dosomething/2),
> with the left out parameters filled in with default values automatically.
> 
> A Prologesque solution might be:
> 
> |:- pred cmd(string,list(cmdarg),cmdproc).
> |:- mode cmd(out,out,out) is nondet.
> |
> |cmd( "command", [],              dosomething(0,"filename") ).
> |cmd( "command", [str(F)],        dosomething(0,F)          ).
> |cmd( "command", [int(N)],        dosomething(N,"filename") ).
> |cmd( "command", [str(F),int(N)], dosomething(N,F)          ).
> 


> where the cmdarg and cmdproc types are fine, but the compiler chokes on
> the modes. Am I right in seeming to remember this is not supported, but
> that there have been some work on it, but not everybody agrees it is
> useful at all?
> 
> The last discussion on the mailing list seems to have been in 1999.

The problem with partial instantiation is that it makes the
implementation of the language much more complex and can lead
to surprising results.  Mercury requires that the compiler be
able to deduce exactly where in the program each variable
becomes ground; this can't happen when you don't specify the
modes, which is the problem you have here.

However, looking at your program, it seems to me that you know what
command you mean and what F and N are at the point where you call cmd/3,
so why not use this mode:

:- mode cmd(in, in, out) is nondet.

You can then do things like

	cmd("command", [str("filename")], Cmd1),
	cmd("command", [int(N)], Cmd2),
	...

-- Ralph
--------------------------------------------------------------------------
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