I was recently looking at the wikipedia page for dependent types, and I was wondering; does Perl 6 actually introduce dependent types? I can't seem to find a reliable source claiming that.
It might be obvious to some, but it sure as heck ain't obvious to me.
Against Ven, in the comments following the Perl 6 answer to the SO question "Is there a language with constrainable types?", wrote "perl6 doesn't have dependant types" and later wrote "dependent type, probably not, ... well, if we get decidable
where
s..." in an exchange on #perl6. (Larry Wall's response was "what's a few halting problems among friends". Btw, by far the best way to get an authoritative answer on all things Perl 6 is to ask TimToady via #perl6.)For The summary for the 'dependent-type' SO tag is "Dependent types are types that depend on values." Perl 6 supports types that depend on values, so there's that.
For The edit summary for the change by Awwaiid that added Perl 6 to Wikipedia's page on Dependent Types says "Perl 6 ... has undecidable dependent types".
The Wikipedia page starts with:
Here's one way to create a type along those lines in Perl 6:
Does this mean the Perl 6
subset
feature generates dependent types? Perhaps this is what Awwaiid is thinking of.Arguably yes as subsets are types that may depend on arbitrary conditions. However, the type system would be classified as unsound as type invariants are not enforced.
In particular, a variable's type constraint is only checked on assignment, so modifications to an object that make it drop from a subset will lead to a variable holding an object it should not be able to, eg
You can use some meta-object wizardry to make the object system automatically check the type after any method call by boxing objects in transparent guard objects.
A naive implementation could look like this:
This will make the following fail: