in reply to Re^3: Static typing is mostly a waste of time
in thread Static typing is mostly a waste of time
Or unless you have a type "Non-negative number".
Which you can define easily in Perl 6 :):
my subtype NonNegativeNumber of Num where { not $^a < 0 }; my NonNegativeNumber $x = 3; # works my NonNegativeNumber $y = -3; # dies
Another example of using subtypes:
my subtype HTTP::Request::Method of Str where { $^method eq any <GET POST HEAD ...>; }; method send_using(HTTP::Request::Method $method) { ...; # Note: You don't have to manually check for $method # not being a valid HTTP method :). }
--Ingo
|
|---|