<div class="gmail_quote">On 30 January 2012 22:03, Julien Fischer <span dir="ltr"><<a href="mailto:juliensf@csse.unimelb.edu.au">juliensf@csse.unimelb.edu.au</a>></span> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The compiler's support for inst subtyping like this is a bit flakey.<br>
Nevertheless, it's possible to write a version of apply/3 that only<br>
accepts input lists of even length -- depending on the circumstances<br>
it may not be possible to call it however.<br></blockquote><div><br></div><div>That sounds ominous… :)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
:- inst evenlist == bound([] ; [ground | oddlist]).<br>
:- inst oddlist == bound([ground | evenlist])<br></blockquote><div><br></div><div>That's the kind of stuff I was toying with, but …</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Unfortunately, the above won't work since to use the new definition the<br>
_compiler_ needs to be able to prove that the output of the call to<br>
list.zip/2 also has the inst evenlist. (Which is not possible given<br>
the definition of zip/2.)<br></blockquote><div><br></div><div>…this was the bar my head kept hitting.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"> main(!IO) :-<br>
Forward = [math.sin, math.cos, (func(X) = math.ln(X))],<br>
Reverse = [math.asin, math.acos, (func(X) = math.exp(X))],<br></div>
Results = list.map_corresponding(<br>
(func(F, R) = compose(R, F, 0.5)), Forward, Reverse),<div class="im"><br>
io.write_list(Results, ", ", io.write_float, !IO),<br>
io.write_string("\n", !IO).<br></div></blockquote><div><br></div><div><b>THIS</b> is awesome, however! There's a lot of stuff in the standard library, but the documentation is … a wee bit terse. I completely overlooked that one. I'm going to have to spend a few years on the library docs it seems. :)</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"> main(!IO) :-</div><div class="im">
Forward = [math.sin, math.cos, (func(X) = math.ln(X))],<br>
Reverse = [math.asin, math.acos, (func(X) = math.exp(X))],<br></div>
apply(assoc_list.from_<u></u>corresponding_lists(Forward, Reverse),<div class="im"><br>
[], Results),<br>
io.write_list(Results, ", ", io.write_float, !IO),<br>
io.write_string("\n", !IO).<br>
<br></div>
:- pred apply(assoc_list((func(float) = float)), list(float),<div class="im"><br>
list(float)).<br>
:- mode apply(in, in, out) is det.<br>
<br>
apply([], A, Results) :- Results = A.<br></div>
apply([F - R | Functions], A, Results) :-<div class="im"><br>
apply(Functions, [compose(R, F, 0.5) | A], Results).<br></div></blockquote><div><br></div><div>I'm not sure I understand this one at all, however. I mean I understand my apply/3 predicate still, even with the funky F - R match there, but would you mind walking me through the rest of this a bit? </div>
</div><div><br></div>-- <br>"Perhaps people don't believe this, but throughout all of the discussions of entering China our focus has really been what's best for the Chinese people. It's not been about our revenue or profit or whatnot."<br>
--Sergey Brin, demonstrating the emptiness of the "don't be evil" mantra.<br>