Ovid wrote:
Specifically, I was looking for the documentation on how subsets work
See S12:
http://dev.perl.org/perl6/doc/design/syn/S12.html#Types_and_Subtypes

as it looks like we can get declarative style constraint programming
for free:

  subset Crosshair of Point where { $_.inside_of($target_zone) };

Is that valid syntax?
Yes. I presented some slides on it, under the name "dependant types", at the NPW recently.
http://www.jnthn.net/papers/2008-npw-understanding-perl6-slides.pdf

Aside: you can play with them in Rakudo somewhat, if you want to get a feel for them a bit more. You can declare them just fine with the syntax you wrote above; you can also declare anonymous ones on subroutine parameters too (and refer to other parameters inside them) and they will be enforced, plus they will be enforced on variables. Lexically scoping them and the "my Str Foo where ..." forms likely don't work just yet, though, and they don't yet act as tie-breakers in MMD.

Hope this helps,

Jonathan

Reply via email to