5 ms·
Rust, Generics, and Collections
- ludamad 12y agoIt'd be nice if the examples had syntax highlighting.
- kibwen 12y agoHa, that trick with `Map<T, ()>` is actually really neat, and I'm happy to see that there's no qualms about its efficiency that would preclude its use in the standard library. This post has inadvertently become the most thorough documentation on zero-sized types that I know of, in addition to being the gold standard for guiding people interested in implementing data structures in Rust. :)
- Gankro 12y agoAnd I completely forgot about how they can be used to give collections "chunks" of code to run without the need for function pointers! And how you can use unboxed closures with no captures to make a zero-sized bundle of static-data. Ah well. More stuff for part-2.
- throwaway928 12y agoWhy not use `fold` to implement `find_min`?
- Gankro 12y agoWell I mean if you want to cheat with iterator adaptors you can just use min_by: http://doc.rust-lang.org/std/iter/trait.IteratorExt.html#tymethod.min_by http://doc.rust-lang.org/std/iter/trait.IteratorExt.html#tym... :P (shhh I was tired and trying to come up with a simple but moderate complexity example)
- yazaddaruvala 12y agoHey @Gankro, your blah/ dir doesn't have an index of all files. Unless you know the links for these Rust posts, you can't really navigate to them. Especially if you keep posting, which you should, I'd keep in mind the navigation to and from these rust-lang posts.
- Gankro 12y agoThere is a blah/rss.xml, but yeah that's on my TODO. Maybe for the next post.
- avz 12y agoInterestingly, if we limit ourselves to pure functions, a ZST corresponds to category-theoretic concept of the terminal object. The latter is defined as such an object (think "type") T that for any other object (think "another type") X there is precisely one arrow (think "function") from X to T [1]. Indeed, if T is a ZST like the empty tuple () then for any type of argument there is precisely one function to T: namely, the one returning T's sole value, (). Also, Result<T, E> is an example of a variant type corresponding neatly to co-products [2]. [1] http://en.wikipedia.org/wiki/Initial_and_terminal_objects http://en.wikipedia.org/wiki/Initial_and_terminal_objects [2] http://en.wikipedia.org/wiki/Coproduct http://en.wikipedia.org/wiki/Coproduct