[mercury-users] sqrt.m:005: error: determinism declaration not satisfied.
Ralph Becket
rbeck at microsoft.com
Fri Apr 27 19:42:51 AEST 2001
> From: Terrence Brannon [mailto:princepawn at earthlink.net]
>
> [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'.
>
> ... what can I do? everything works when I hardcode the number to find
> the square root of, but I am trying to get it from the command
> line.. Entire program included for reference.
> [...]
>
> % 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).
string__to_float/2 is semidet (i.e. it has zero or one solutions) making
your if-then-else goal semidet making the whole body of main//0 semidet.
string__to_float/2 is semidet because its first argument may not be a
valid string representation of a float.
main//0 must be det or cc_multi because it affects the io__state.
You therefore need to make your code deterministic:
main -->
io__command_line_arguments(ArgV),
{ X = ( if ArgV = [Arg1 | _], string__to_float(Arg1, X0)
then X0
else 12.0
)
},
io__write_float(sqrt(X)),
io__nl.
-- Ralph
--------------------------------------------------------------------------
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