Hi Jörn,
I will answer your question in a general sense, since it may be
helpful for others in other settings; I hope you don't mind.
First, let's take a look at the truth table for logical implication:
p q p -> q
0 0 1
1 0 0
0 1 1
1 1 1
We see here that if p is false, then the value for the equation can be
determined without inspecting q (it's true!). This is a bit like &&
and || that are also lazy in their second argument. We want the same
for 'implies' so that the expression that is used for the value of 'q'
is not necessarily evaluated. Unfortunately, Java makes this a little
difficult, so you'll find two versions of the implies method. The one
you have used will evaluate both sides of the equation regardless but
is slightly easier to use.
Imagine a Java && that did this:
if(s != null && !s.isEmpty()) // ugh if s == null, we will get a NPE.
So, to actually answer your question; there is a version of 'implies'
that accepts a P1<Property> [1] and you can get a Property from a
boolean using the prop function [2]. (By the way, is Generator your
own type?)
return bool(range > size).implies(new P1<Property>() {
public Property _1() {
return prop(new Generator().generate(size, range).size() == size);
}
}
I hope this helps Jörn, but if not, please feel free to ask for more
clarification.
PS: I saw your comment on my blog, but Rickard beat me to answering :)
[1]
http://projects.workingmouse.com/public/reductio/artifacts/2.2//javadoc/reductio/Bool.html#implies(fj.P1)
[2]
http://projects.workingmouse.com/public/reductio/artifacts/2.2//javadoc/reductio/Property.html#prop(boolean)
- --
Tony Morris
http://tmorris.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFISE9CmnpgrYe6r60RAtpJAKC5PhSrHZ5BYhZbh1mIEyX5HZu6NgCdFu1K
PLLNZx+bObGo/qvLortFpck=
=iaM8
-----END PGP SIGNATURE-----
Ricky Clarkson wrote:
> I apologise. I invented F0 and Pair and didn't look at what
> Reductio and Functional Java provide. I could say I left that as an
> exercise for the reader, but really I was just being lazy and hoping
> you understood :)
Thanks Ricky for taking care of things while I was snoozing ;)
Functional Java provide fj.P1 and fj.P2 respectively for this scenario.
I'd also like add that Scala permits call-by-name function values, so
this problem does not pop up. Also, it allows non-alphanumeric method
names, so instead of 'implies' the method is called -> The scaladoc
for this function is here:
Note the annotation (=>) on the argument denoting its evaluation strategy.
You can see an example of the use of the -> method here:
http://reductiotest.org/examples/scala#IntegerOverflow
- --
Tony Morris
http://tmorris.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFISFN0mnpgrYe6r60RAiYQAKCK4vOAr0I4U/uG4GUCDakM5DZwBgCfakmz
WhVmaFc20dKMKKOi4zrFOPI=
=fZT1
-----END PGP SIGNATURE-----