Dave Whipp wrote:
Darren Duncan wrote:
Dave Whipp wrote:
sub sqrt(Num where { 0 <= $_ <= Real::Max } $x) {
(0..$x/2 :by(Real::Epsilon)).min: { abs $x - $^candidate ** 2 }
}
So do you really mean "as declarative a manner as possible"? Or would
you consider this example to go beyond "possible"?
I would declare sqrt this way instead (the body is the important change):
sub sqrt(Num where { 0 <= $_ <= Real::Max } $x) {
$x ** (1/2)
}
In other words, you prefer explicit definition to implicit declaration
(in this case, you're basically saying that "sqrt" is a curried
exponentiation). Do you have any examples of what you'd propose as
declarative forms for prelude.pm?
I don't quite follow you. Are you saying your version of sqrt is an implicit
declaration; maybe I don't understand how that differs from an explicit
definition in this case? In any event, right at this moment I can't think of an
answer to your question. Go ahead with what you think works and I'll just speak
up later if I have something constructive to offer. -- Darren Duncan