[mercury-users] sqrt.m:005: error: determinism declaration not satisfied.

Peter Ross peter.ross at miscrit.be
Fri Apr 27 19:54:48 AEST 2001


On Fri, Apr 27, 2001 at 01:59:51AM -0700, Terrence Brannon wrote:
> [localhost:~/src/mercury/sqrt] metaperl% mmc -E --infer-all sqrt.m
> sqrt.m:005: In `main(di, uo)':
> sqrt.m:005:   error: determinism declaration not satisfied.
> sqrt.m:005:   Declared `det', inferred `semidet'.
> sqrt.m:080:   call to `to_float(in, out)' can fail.
> 
> ... so when I got this error, I changed main/2 to semi det. Then I was
> told:
> 
> [localhost:~/src/mercury/sqrt] metaperl% mmc -E --infer-all sqrt.m
> sqrt.m:005: Error: main/2 must be `det' or `cc_multi'.
> 

The simple answer is that you must make main det or cc_multi.

[snip]

> 
> % main --> { X = sqrt(22.4) }, io__print(X), io__nl.
> main -->
> 	io__command_line_arguments(ArgV),
> 	{ if ArgV = [Arg1 | _] then string__to_float(Arg1,X) else (X = 12.0) }, > 	{ Answer = sqrt(X) },
> 	io__print(Answer).
> 

main -->
	io__command_line_arguments(ArgV),
	{ if ArgV = [Arg1 | _] then 
			% This predicate is semidet hence main is
			% semidet
		string__to_float(Arg1,X)
	else
		(X = 12.0)
	},
	{ Answer = sqrt(X) },
 	io__print(Answer).
    
To convert a semidet piece of code into a det piece of code you need to
wrap the semidet code in an if then else.

	{ if string__to_float(Arg1, X0) then
		X = X0
	else
		% Do something else to set X, or print an error or
		% whatever
		X = ...
	}

Of course you already have an if-then-else so you could simply move the
call to string_to_float into its condition.

		% If Argv has an Arg1 and we can convert Arg1 to X0
	{ if (ArgV = [Arg1 | _], string__to_float(Arg1, X0)) then 
		X = X0
	else
		(X = 12.0)
	}

HTH
Pete
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list