<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jun 27, 2015 at 11:27 PM, Mark Brown <span dir="ltr"><<a href="mailto:mark@mercurylang.org" target="_blank">mark@mercurylang.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Charles,<br>
<br>
On Sun, Jun 28, 2015 at 7:47 AM, Charles Shuller<br>
<<a href="mailto:charles.shuller@gmail.com">charles.shuller@gmail.com</a>> wrote:<br>
> Hello All,<br>
><br>
> I can't get a predicate to execute from a discriminated union after passing<br>
> the type as a parameter into a predicate. Though it works just fine from<br>
> main.<br>
><br>
> I've tried everything I can think of with modes and insts on the DU, but<br>
> nothing has worked, any insight would be much appreciated.<br>
<br>
To make any call Mercury needs to know the type, mode and determinism<br>
of what is being called. For higher order terms, this information<br>
comes from the inst of the term (see reference manual, 8.3). Functions<br>
have an obvious default they can use, but for predicates this<br>
information must be given somewhere.<br>
<br>
In the signature of execute_test/4, the Test argument is declared<br>
'in', meaning that its inst is ground. Mercury can't determine what<br>
mode and determinism you intend the call to Test^test_pred to be made<br>
in (and neither can I, for that matter). The problem is not the<br>
discriminated union, but the fact that it is declared to be ground.<br>
<br>
><br>
> :- type test<br>
> ---> test(test_name::string,<br>
> test_pred::pred(disposition)).<br>
<br>
The inst you need to declare would look something like:<br>
<br>
:- inst test == bound(ground, pred(m) is d).<br>
<br>
where m and d represent the mode and determinism.<br>
<br></blockquote><div><br></div><div>No joy. bound/2 is not defined.<br><br></div><br><div>:- inst test<br> ---> test(ground, pred(out) is semidet).<br><br></div><div>Is as close as I'd managed to get on my own, but even with that declaration it still doesn't seem able to figure out inst of test_pred and I get the same error message.<br></div><div><br><br><div>Also, I got the idea that the :-inst name == bound(...;...;...) form of inst was creating a name for
an inst-tree which could later be applied as a mode, was that
completely wrong??<br></div><br><br><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
><br>
> :- pred execute_test(test::in, disposition::out, io::di, io::uo) is det.<br>
<br>
Then you can say:<br>
<br>
:- pred execute_test(test::in(test), disposition::out, io::di, io::uo) is det.<br>
<br>
> execute_test(Test, Disposition, !IO) :-<br>
> call(Test^test_pred, Disposition), %% Compilation fails here<br>
> Disposition = fail(Test^test_name ++ " Failed to execute").<br>
><br>
> main(!IO) :-<br>
> Test = test("PassTest", pass_test),<br>
> call(Test^test_pred, Disposition). %% This works just fine though<br>
<br>
This would work because Mercury infers the correct inst of Test from<br>
the mode and determinism of pass_test/1.<br>
<br>
Hope this helps,<br></blockquote><div><br><br></div><div>A bit ;)<br><br></div><div>I now know for sure it's a problem getting the inst declared on test_pred, and I just need to find the correct syntax.<br><br></div><div>I also know it's not a compiler bug, and that there was just more context for inference in the call in main(...).<br><br><br><br></div><div>Thanks!<br><br><br></div><div>Charles<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Mark.<br>
<br>
><br>
><br>
><br>
> Compiler Output (14.01.1)<br>
> ----------------------------------------------------------------------------<br>
><br>
> manual_test.m:044: In clause for `execute_test(in, out, di, uo)':<br>
> manual_test.m:044: in argument 1 (i.e. the predicate term) of higher-order<br>
> manual_test.m:044: predicate call:<br>
> manual_test.m:044: mode error: variable `V_10' has instantiatedness<br>
> `ground',<br>
> manual_test.m:044: expecting higher-order pred inst (of arity 1).<br>
><br>
><br>
> Thanks!<br>
><br>
> Charles<br>
><br>
> _______________________________________________<br>
> users mailing list<br>
> <a href="mailto:users@lists.mercurylang.org">users@lists.mercurylang.org</a><br>
> <a href="https://www.mercurylang.org/lists/listinfo/users" rel="noreferrer" target="_blank">https://www.mercurylang.org/lists/listinfo/users</a><br>
><br>
_______________________________________________<br>
users mailing list<br>
<a href="mailto:users@lists.mercurylang.org">users@lists.mercurylang.org</a><br>
<a href="https://www.mercurylang.org/lists/listinfo/users" rel="noreferrer" target="_blank">https://www.mercurylang.org/lists/listinfo/users</a><br>
</blockquote></div><br></div></div>