[rust-dev] tutorial on interfaces: bounded type parameters

Graydon Hoare graydon at mozilla.com
Thu Jan 12 13:18:11 PST 2012


On 12/01/2012 1:10 PM, Graham Fawcett wrote:

> Note the phrase "aren't known at compile time." That reads as if bounded types
> offer runtime polymorphism. (They don't, do they?)

They do! :)

The very interesting thing about the way interfaces worked out is that 
they managed to unify a whole pile of concepts at once:

   - Static overload dispatch (a la C++ non-virtual methods)
   - Per-type dynamic dispatch (a la typeclasses, caller passes vtbl)
   - Per-value dynamic dispatch (a la C++ virtual methods, @val has vtbl)
   - Separate type kinds (compiler provides impl of reserved iface)

This broad applicability of the *same* language-UI concept was sort of 
the winning argument about why they were worth trying. The theory is 
that much of the time the user doesn't *really* care which of these is 
happening under the hood, and don't need to: they just want whichever 
makes sense given what they've written. So it's nice that they can all 
emerge semi-coherently from the same construct, when used in varying 
contexts.

I've still not given them a serious exploration but I am pretty excited.

-Graydon


More information about the Rust-dev mailing list