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?

Reply via email to