[mercury-users] partial instantiation?

Paul Bone pbone at csse.unimelb.edu.au
Wed Apr 14 12:48:14 AEST 2010


On Wed, Apr 14, 2010 at 03:36:42AM +0200, Tomas By wrote:
> 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 problem is that P and N are never instantiated.  

You might find that the modes.

:- mode cmd(in, in, out) is semidet.
:- mode cmd(out, out, in) is det.

do work, because N and P are bound as one of cmd's inputs.

Alternatively, if you did want partial instantiation, and I don't think you do,
you would have to use a different mode rather than out, out, out that describes
the partial instantiation.

Good luck.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/users/attachments/20100414/40a8f597/attachment.sig>


More information about the users mailing list