3 ms·
You might be interested in the type system of Perl 6: subset Filename of Str where { $_ ~~ :f }; Here you define the Filename type as a string that repres
by zoul 15y ago
You might be interested in the type system of Perl 6:
subset Filename of Str where { $_ ~~ :f };
Here you define the Filename type as a string that represents an existing path. This particular example is a horrendous hack of course, but the tool looks very interesting. Not sure if this can be used for performance tuning in existing P6 implementations.
- rjh29 15y agoThat's a horrible hack indeed :) Perl 6 does have 'gradual typing' though. You can define a variant: my $foo; or a typed variable: my Int $foo; or a subtype with arbitrary restrictions subset OneToTen of Int where { 1 <= $^n <= 10 }; my OneToTen $foo; Or... (http://rosettacode.org/wiki/Define_a_primitive_data_type#Perl_6 http://rosettacode.org/wiki/Define_a_primitive_data_type#Per...) subset Prime of Int where { $^n > 1 and $^n %% none 2 .. sqrt $^n }; Perl 6 scares me.