[rust-dev] Functions overloading

David Rajchenbach-Teller dteller at mozilla.com
Thu Apr 12 03:01:34 PDT 2012


On Thu Apr 12 10:08:21 2012, Alexander Stavonin wrote:
> What's about function overloading? Something like this:
>
> fn foo(val: int) {
>     io::println("int");
> }
>
> fn foo(val: str) {
>     io::println("str");
> }
>
> fn main() {
>     foo(1);
>     foo("test");
> }
>
> But :(
>
> main.rs:3:0: 5:1 error: duplicate definition of foo
> main.rs:3 fn foo(val: int) {
> main.rs:4     io::println("int");
> main.rs:5 }
>
> As I understood, similar code can be implemented by using ifase and impl, but it's very cumbersome way.
My personal experience is that you want function overloading to be very 
explicit. Having too much overloading makes it much easier to misread 
code.

So, I personally would not advocate C++-style function overloading.

--
David Rajchenbach-Teller, PhD
 Performance Team, Mozilla

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: OpenPGP digital signature
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20120412/de736bad/attachment.bin>


More information about the Rust-dev mailing list