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

Josh Haberman jhaberman at gmail.com
Fri Jul 25 15:20:37 PDT 2014

On Fri, Jul 25, 2014 at 10:34 AM, Patrick Walton <pcwalton at mozilla.com>

> On 7/25/14 10:10 AM, Josh Haberman wrote:
>> On Fri, Jul 25, 2014 at 10:04 AM, Patrick Walton <pcwalton at mozilla.com>
>> wrote:
>>> Neither auto-ref or ad-hoc operator overloading
>>> would let you write a generic function that calls
>>> `pow` and works optimally with both bigints and
>>> ints. I think the only thing that would work is
>>> something like C++ ad-hoc templates, which is
>>> a road I don't want to go down.
>> Could you explain what you mean by "ad-hoc templates", and how this
>> differs from Rust's templates?
> In Rust you can never have type errors during template expansion. If a
> call to a generic/template typechecks properly, then the template is
> guaranteed to expand to valid Rust code with no type errors within it. This
> is done via the trait system, which is similar in spirit to the concept
> systems proposed for C++17 (the difference being that Rust *only* has
> concepts).

Got it. So the "ad hoc" part refers to having a template parameter, but not
being able to check its capabilities/interface at template
parsing/typechecking time, it sounds like?

How does the trait/concept approach preclude template specialization? Each
template specialization could be independently type-checked, but the most
specialized one could be selected at instantiation time. Or is this
considered "overloading" and discarded because of the extra complexity? I
guess it could be complicated to define which was "most specialized."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140725/dec7e02b/attachment.html>

More information about the Rust-dev mailing list