Re: [rust-dev] Functions overloading

2012-04-18 Thread Steven Blenkinsop
On Wednesday, April 18, 2012, Alexander Stavonin wrote: > Stefan, I understood you idea but I have problem with compilation. > > fn_overloading.rs:31:34: 31:80 error: method `to_input` has an > incompatible type: type parameter vs int > fn_overloading.rs:31 impl of to_input for int { fn to_input(

Re: [rust-dev] Functions overloading

2012-04-18 Thread Niko Matsakis
On 4/18/12 4:26 PM, Alexander Stavonin wrote: Stefan, I understood you idea but I have problem with compilation. fn_overloading.rs:31:34: 31:80 error: method `to_input` has an incompatible type: type parameter vs int fn_overloading.rs:31 impl of to_input for int

Re: [rust-dev] Functions overloading

2012-04-18 Thread Alexander Stavonin
Stefan, I understood you idea but I have problem with compilation. fn_overloading.rs:31:34: 31:80 error: method `to_input` has an incompatible type: type parameter vs int fn_overloading.rs:31 impl of to_input for int { fn to_input() -> input { ret val(self); } } ^~~~

Re: [rust-dev] Functions overloading

2012-04-16 Thread Niko Matsakis
On 4/16/12 5:58 PM, Stefan Plantikow wrote: I think it would be nice too have some syntax support for building ifaces like that, perhaps via macros. I can see this approach being useful in cases of multiple inputs. In any case, it reminds me of this bug: https://github.com/mozilla/rust

Re: [rust-dev] Functions overloading

2012-04-16 Thread Stefan Plantikow
Hi, Am Donnerstag, 12. April 2012 um 15:47 schrieb Niko Matsakis: > Not only that, but it adds an extra layer of complexity for type > inferencing, which quite frankly is already complex enough. > > That said, you can do a limited form of overloading using impls: > > impl methods for int { >

Re: [rust-dev] Functions overloading

2012-04-12 Thread Alexander Stavonin
I suppose this style is less confused. foo(i(10)); foo(s("test")); than this one, at least for passing parameters to a function. 10.foo(); "test".foo(); 13 апреля 2012 г. 14:00 пользователь Niko Matsakis написал: > On 4/12/12 9:30 PM, Alexander Stavonin wrote: > >> The closest

Re: [rust-dev] Functions overloading

2012-04-12 Thread Niko Matsakis
On 4/12/12 9:30 PM, Alexander Stavonin wrote: The closest variant can be implemented by using enums, but I can't say that resulted code is nice.: What is wrong with the impl-based technique I suggested? Niko ___ Rust-dev mailing list Rust-dev@mozill

Re: [rust-dev] Functions overloading

2012-04-12 Thread Alexander Stavonin
The closest variant can be implemented by using enums, but I can't say that resulted code is nice.: enum foo_param { i(int), s(str) } fn foo(param: foo_param) { alt param { i(int_val) { io::println(#fmt("foo was called with int == %d", int_val)); }

Re: [rust-dev] Functions overloading

2012-04-12 Thread Niko Matsakis
Not only that, but it adds an extra layer of complexity for type inferencing, which quite frankly is already complex enough. That said, you can do a limited form of overloading using impls: impl methods for int { fn foo() { ... } } impl methods for uint { fn foo() { ... } } Niko O

Re: [rust-dev] Functions overloading

2012-04-12 Thread David Rajchenbach-Teller
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:

[rust-dev] Functions overloading

2012-04-12 Thread Alexander Stavonin
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: