News for hackers. Stuff that matters.
Re:Announcing Rust 1.0 Alpha by mopo2000 on Friday January 09, 2015 @03:09PM (#8864203)
How can you have an alpha without generics?
Re:Announcing Rust 1.0 Alpha by nercury on Friday January 09, 2015 @03:16PM (#8864245)
You can read up here: http://doc.rust-lang.org/book/generics.html, as well about "output" generics here: https://github.com/rust-lang/rfcs/blob/master/text/0195-asso..., and explore usage in collections here: http://doc.rust-lang.org/nightly/std/collections/.
Re:Announcing Rust 1.0 Alpha by 12423gsd on Friday January 09, 2015 @05:19PM (#8864851)
Are "Traits" basically C++ Concepts?
Re:Announcing Rust 1.0 Alpha by adrusi on Friday January 09, 2015 @06:26PM (#8865139)
Somewhere between C++ concepts and Haskell typeclasses with a hint of Java interfaces.

But yes, their primary usage is to require that type parameters exhibit a certain set of properties.

Re:Announcing Rust 1.0 Alpha by nercury on Friday January 09, 2015 @05:54PM (#8865014)
For someone who knows C#, I would explain them as abstract extension methods that can be overriden for specific types.
Re:Announcing Rust 1.0 Alpha by bjz_ on Saturday January 10, 2015 @01:19AM (#8866135)
They fill the same role as concepts - ie. bringing type checking to the call site when using parametrized types, rather than using a duck typed approach, which leads to the big template stack traces that you get in C++.
Re:Announcing Rust 1.0 Alpha by steveklabnik on Friday January 09, 2015 @05:42PM (#8864958)
There are some technical details that make them different, if I recall correctly. But they're kinda similar. They're also close to Haskell's typeclasses.
Re:Announcing Rust 1.0 Alpha by Twisol on Friday January 09, 2015 @03:14PM (#8864236)
I think you misunderstood something somewhere. This alpha definitely has generics. For example:

    enum Option<T> { Some{value: T}, None }
Re:Announcing Rust 1.0 Alpha by steveklabnik on Friday January 09, 2015 @03:12PM (#8864220)
We have them.
Re:Announcing Rust 1.0 Alpha by Gankro on Friday January 09, 2015 @04:55PM (#8864765)
Like three different kinds, too!

        // Old-style generics; monomorphized 
        // with S as an "input" type of MyTrait
        fn foo<S, T: MyTrait<S>>(elem: T) { ... }

        // Where-clause-style generics; monomorphized, 
        // with S as an "output" (associated) type of MyTrait
        fn foo<S, T>(elem: T) 
        where T: MyTrait<Thing = S> { ... }

        // Trait objects; dynamic dispatch
        fn foo(elem: Box<MyTrait>) { ... }
Re:Announcing Rust 1.0 Alpha by kimundi on Friday January 09, 2015 @08:31PM (#8865487)
Well, the first two are really just the same thing :P
Re:Announcing Rust 1.0 Alpha by Gankro on Saturday January 10, 2015 @12:53AM (#8866081)
Eh, with the new oprhan/impl rules associated and uh... not... associated(...?) types have developed quite a schism.
Re:Announcing Rust 1.0 Alpha by dbaupp on Saturday January 10, 2015 @02:31AM (#8866242)
Well, the first two confusingly change two variables at once: the things that are the same (which I presume is what kimundi meant) are

    fn foo<S, T: MyTrait<S>>(elem: T) { ... }

    fn foo<S, T>(elem: T) where T: MyTrait<S> { ... }
and

    fn foo<S, T: MyTrait<Thing = S>>(elem: T) { ... }

    fn foo<S, T>(elem: T) where T: MyTrait<Thing = S> { ... }
Re:Announcing Rust 1.0 Alpha by nercury on Friday January 09, 2015 @03:18PM (#8864256)
To be fair, there were _some_ languages and frameworks which did not have generics on the 1.0 release. It is a bit strange to assert that a new language should.
Re:Announcing Rust 1.0 Alpha by legulere on Friday January 09, 2015 @05:04PM (#8864801)
It's pretty hard to add them afterwards in a backward-compatible way that is not a great hack
Re:Announcing Rust 1.0 Alpha by pinumbernumber on Friday January 09, 2015 @03:33PM (#8864326)
It does have generics, unless I'm misunderstanding you