Re: [rust-dev] Structural Typing
On 23/03/14 06:34 AM, Ziad Hatahet wrote: Hi all, Are there any plans to implement structural typing in Rust? Something like this Scala code: http://en.wikipedia.org/wiki/Duck_typing#In_Scala Rust used to have structural records. The feature was removed because it's far from orthogonal with traits. It's simply not how things are usually done in Rust, so it's never going to fit in well. More ways to do the same stuff doesn't really help anyone, and fragments the community. signature.asc Description: OpenPGP digital signature ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] Structural Typing
IMO, this is bad. 2014年3月23日 下午6:34于 Ziad Hatahet hata...@gmail.com写道: Hi all, Are there any plans to implement structural typing in Rust? Something like this Scala code: http://en.wikipedia.org/wiki/Duck_typing#In_Scala ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] Structural Typing
I would note that Rust macros are actually working with structural typing: the expanded macro cannot be compiled unless the expressions/statements it results in can be compiled. Regarding Scala here, it seems a weird idea to ask that each and every method should copy+paste the interface. We all know the woes of duplication. Instead, you can define a Trait (even if for a single function) and it'll just work; and when you add a second function you will be able to re-use the same trait. On Sun, Mar 23, 2014 at 11:37 AM, Liigo Zhuang com.li...@gmail.com wrote: IMO, this is bad. 2014年3月23日 下午6:34于 Ziad Hatahet hata...@gmail.com写道: Hi all, Are there any plans to implement structural typing in Rust? Something like this Scala code: http://en.wikipedia.org/wiki/Duck_typing#In_Scala ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] Structural Typing
You wouldn't probably use this for each and every method, but what it gives you is Go-style duck typing. Sure you can define a trait, but what if the struct you to pass to your function does not implement it? I guess you would have to implement a wrapper around it manually then. -- Ziad On Sun, Mar 23, 2014 at 4:37 AM, Matthieu Monrocq matthieu.monr...@gmail.com wrote: I would note that Rust macros are actually working with structural typing: the expanded macro cannot be compiled unless the expressions/statements it results in can be compiled. Regarding Scala here, it seems a weird idea to ask that each and every method should copy+paste the interface. We all know the woes of duplication. Instead, you can define a Trait (even if for a single function) and it'll just work; and when you add a second function you will be able to re-use the same trait. On Sun, Mar 23, 2014 at 11:37 AM, Liigo Zhuang com.li...@gmail.comwrote: IMO, this is bad. 2014年3月23日 下午6:34于 Ziad Hatahet hata...@gmail.com写道: Hi all, Are there any plans to implement structural typing in Rust? Something like this Scala code: http://en.wikipedia.org/wiki/Duck_typing#In_Scala ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] Structural Typing
On 3/23/14 2:19 PM, Ziad Hatahet wrote: You wouldn't probably use this for each and every method, but what it gives you is Go-style duck typing. Sure you can define a trait, but what if the struct you to pass to your function does not implement it? I guess you would have to implement a wrapper around it manually then. I don't think Go-style duck typing turns out to be that useful in practice to solve this problem, because the chances that two independently-developed libraries that wanted to expose some functionality on their object, say, `Munge()`, would give the function exactly the same name and give exactly the same types to its arguments, (in the same order!) is astronomically small. In reality the primary benefit of Go-style duck typing is the ability to avoid having to type the name of the trait you're implementing at the implementation site. What you give up for this is the ability to provide extension methods: i.e. implementation of a trait for a type *outside* of the package that defined the type. This is a huge downside, and I don't think it's worth it on the whole; this is why Rust's traits are designed the way they are. Patrick ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] Structural Typing
+1 2014年3月24日 上午5:46于 Patrick Walton pcwal...@mozilla.com写道: On 3/23/14 2:19 PM, Ziad Hatahet wrote: You wouldn't probably use this for each and every method, but what it gives you is Go-style duck typing. Sure you can define a trait, but what if the struct you to pass to your function does not implement it? I guess you would have to implement a wrapper around it manually then. I don't think Go-style duck typing turns out to be that useful in practice to solve this problem, because the chances that two independently-developed libraries that wanted to expose some functionality on their object, say, `Munge()`, would give the function exactly the same name and give exactly the same types to its arguments, (in the same order!) is astronomically small. In reality the primary benefit of Go-style duck typing is the ability to avoid having to type the name of the trait you're implementing at the implementation site. What you give up for this is the ability to provide extension methods: i.e. implementation of a trait for a type *outside* of the package that defined the type. This is a huge downside, and I don't think it's worth it on the whole; this is why Rust's traits are designed the way they are. Patrick ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] Structural Typing
Thanks for the feedback everyone. It makes sense how things currently are for Rust. Keep up the great work! -- Ziad On Sun, Mar 23, 2014 at 4:54 PM, Liigo Zhuang com.li...@gmail.com wrote: +1 2014年3月24日 上午5:46于 Patrick Walton pcwal...@mozilla.com写道: On 3/23/14 2:19 PM, Ziad Hatahet wrote: You wouldn't probably use this for each and every method, but what it gives you is Go-style duck typing. Sure you can define a trait, but what if the struct you to pass to your function does not implement it? I guess you would have to implement a wrapper around it manually then. I don't think Go-style duck typing turns out to be that useful in practice to solve this problem, because the chances that two independently-developed libraries that wanted to expose some functionality on their object, say, `Munge()`, would give the function exactly the same name and give exactly the same types to its arguments, (in the same order!) is astronomically small. In reality the primary benefit of Go-style duck typing is the ability to avoid having to type the name of the trait you're implementing at the implementation site. What you give up for this is the ability to provide extension methods: i.e. implementation of a trait for a type *outside* of the package that defined the type. This is a huge downside, and I don't think it's worth it on the whole; this is why Rust's traits are designed the way they are. Patrick ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev