[rust-dev] std::num::pow() is inadequate / language concepts

Gregor Cramer remarcg at gmx.net
Fri Jul 25 12:36:35 PDT 2014


> Did I miss a point in this thread where using a typeclass/trait to
> implement exponentiation was dismissed?
>
> This function could be changed to:
>
>   fn pow<T: HasPow>(base: T, exp: uint) -> T { base.pow(exp) }
>
> trait HasPow {
>   fn pow(self: Self, exp: uint) -> Self
> }
>
> Or, just use HasPow in your code.

Yes, you missed a point, I've already pointed out in my initial mail that
moving pow() into a trait (that's what your code is finally doing) is solving
this special problem, but it is not solving a general problem with (other)
functions. A new module may cause that an older function (which you
cannot overload) is inadequate. This makes software instable. In the past
(with some older programming languages) you did not have solutions for
this, but Rust is 2014, programming and compiler techniques have evolved.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140725/debf214e/attachment.html>


More information about the Rust-dev mailing list