Typing sounds like a good thing. It's almost always not. Why? Because we get lost in the idea of "correctness," and so what looks like:
sub fibonacci (PositiveInt $n) {
return 1 if $n <= 1;
return fibonacci($n-1) + fibonacci($n-2);
}
actually reads more like:
sub fibonacci ($n ...
# Wait, wait... hold on a second! What is this $n thing you claim
# to be sending me?! Is this a thing? Is it the kind of thing that
# I approve of? What about my friends? Will my friends respect
# this thing? Let's ask them... Hold on, now, do I trust my
# friends? Maybe not. Better take some precautions...
# Time for some state management in the form of eval. That's light
# weight, right?
# Also, now is a good time to pre-format some error messages just
# in case. Okay, I think this $n thing is up to snuff, but just in
# case, I'm going to do some state management. Hold on a bit...
) {
return 1 if $n <= 1;
return fibonacci($n-1) + fibonacci($n-2);
}
What I'd rather see is the ability to quickly validate, completely under my control, and completely duck-typed. For example:
sub fibonacci($n {$n >= 0 && int($n) == $n}) {
return 1 if $n <= 1;
return fibonacci($n-1) + fibonacci($n-2);
}
Where this expands to something more or less like:
sub fibonacci($n) {
die '$n failed check "$n >= 0 && int($n) == $n"' unless $n >= 0 &&
+ int($n) == $n;
...
}
I have no problem with typing as a shorthand that people can use if they want, where
sub fibonacci(PostiveInt $n) {
is equivalent to
sub fibonacci($n {$n = PostiveInt->new($n)}) {
But in that case, I've opted in to a potentially very expensive type construction from my potentially very simple value.