<br><br><div class="gmail_quote">On Fri, Sep 3, 2010 at 19:51, Peter Alexander <span dir="ltr">&lt;<a href="http://peter.alexander.au">peter.alexander.au</a>@<a href="http://gmail.com">gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
== Quote from Simen kjaeraas (<a href="mailto:simen.kjaras@gmail.com">simen.kjaras@gmail.com</a>)&#39;s article<br>
<div class="im">&gt; Yes, very much so. However, Peter Alexander has misunderstood the<br>
&gt; ambiguous operator.<br>
<br>
</div>Hey, I was just going by what the guy posted :)  He mentioned<br>
nothing of tuples, and his examples certainly didn&#39;t show any<br>
tuples.<br>
</blockquote></div><br>Yes, I agree with Peter there. As I said, I personally prefer the examples in the SO OP than the Haskell/Ruby code, if only because the example are easily understood and I find this range combinator useful in some circumstances.<br>
What we have here in D is a bit like the List monad in Haskell: a way to represent a bunch of possible values for a computation. If a can 2 or 4 or 6, and b can be 0 or 1 or 2, it makes sense for a*b to among 0,2,4,6,8,12.<br>
<br>So thanks, Peter. But does the code compile for you? As I said, here with 2.048, it doesn&#39;t.<br>
<br>
Now, the &#39;real&#39;/intriguing/mind-bending amb operator (from the 60&#39;s) 
does like the Haskell implementation linked in SO does: backtracking on the results to avoid some condition. If someone is up to the challenge of implementing it in D, great! Maybe with closures? I never really thought about it.<br>
<br>I guess the D syntax would be <br>auto x = amb([1,2,3]);<br>auto y =amb([4,5,6]);<br>x*y == 8; // forces desambiguation =&gt; the ambs explore the possibilities.<br>assert(x == amb([2]));<br>assert(y == amb([4]));<br>
<br>There is only one value left, no more ambiguity. Maybe in this case an &#39;alias possibilities[0] this&#39; could do the trick:<br><br>assert(x == 2);<br>assert(y == 4);<br><br>Can we do alias someArray[0] this; ?<br>
<br><br>Philippe<br><br><br><br><br>Philippe<br><br>