News for hackers. Stuff that matters.
Re:Rust is more than safety by mmstick on Wednesday December 28, 2016 @03:27PM (#13273346)
Rust is very expressive. The main benefits of functional programming languages is contained with Rust's Iterator trait and the ad-hoc polymorphism that traits allow.
Re:Rust is more than safety by kibwen on Wednesday December 28, 2016 @03:32PM (#13273387)
I don't know that traits in Rust are an example of ad-hoc polymorphism, since they're fully type-safe.
Re:Rust is more than safety by burntsushi on Wednesday December 28, 2016 @05:09PM (#13274113)
I don't think that means it isn't ad hoc. Type classes in Haskell were originally introduced as a form of ad hoc polymorphism, for example: http://202.3.77.10/users/karkare/courses/2010/cs653/Papers/a... (One of Wadler's great papers btw, worth a read.)

See also: https://en.wikipedia.org/wiki/Type_class

Of course, Haskell type classes and Rust traits aren't the same. But they are quite similar!

Re:Rust is more than safety by tatterdemalion on Wednesday December 28, 2016 @05:25PM (#13274219)
"ad-hoc polymorphism" is an informal term; traits are sort of both ad hoc and parametric.

I've sometimes imagined someone writing a paper about specialization and naming it "How to make parametric polymorphism less parametric" after Wadler's paper.

Re:Rust is more than safety by mmstick on Wednesday December 28, 2016 @05:22PM (#13274203)
Here's an example: `Stdin` and `File` both implement the `Read` trait. Therefore, you can write a function that takes the traits that you want to use as input parameters.

fn do_something_with<S: Read>(source: S) {

    // do something with input source
}

Then you can do the following:

let stdout = io::stdout();

do_something_with(stdout.lock());

let file = File::open(path).unwrap();

do_something_with(file);

You're free to narrow down/expand the types/methods that can be used with the function if you add more traits.

Re:Rust is more than safety by dllthomas on Wednesday December 28, 2016 @05:21PM (#13274199)
As I understand the term, "ad-hoc polymorphism" refers to dispatch based on types (as opposed to "parametric polymorphism", where one code path works for any type). Nothing to do with type-safety.