News for hackers. Stuff that matters.
Re:Redis re-implemented in Rust by anonfunction on Friday June 19, 2015 @06:16AM (#9743870)
I would hardly say this is readable:

    fn search_entry_hashed<'a, K: Eq, V>(table: &'a mut RawTable<K,V>, hash: SafeHash, k: K)
        -> Entry<'a, K, V>
Re:Redis re-implemented in Rust by pygy_ on Friday June 19, 2015 @07:50AM (#9744098)
I don't know Rust, and the only thing opaque to me in that line is the `'a` syntax. I suppose it is related to memory safety.

In plain English:

`search_entry_hashed` is a parametric function. It works in a type safe way on any kind of K and V. It takes as arguments a reference to a mutable hash table, a hash function and a key, and returns an `Entry` object whose precise type depends on the type of the parameters.

You could hardly express that more succinctly. You can't understand it by skimming it, but it is a complex definition.

Re:Redis re-implemented in Rust by Tuna-Fish on Friday June 19, 2015 @08:02AM (#9744129)
Your guess about 'a is correct. 'a is here used to signify that the return value can only be safely used while the value table exists and is not being concurrently modified. This implies that the value is not copied on return, but only a reference into the table is returned.
Re:Redis re-implemented in Rust by pygy_ on Friday June 19, 2015 @08:20AM (#9744201)
I'm surprised that RawTable isn't parametrized on the type of hash function. Something like this (possibly wrong way to express it, but you get the idea)

    fn search_entry_hashed<'a, K: Eq, V, H: SafeHash>(table: &'a mut RawTable<K,V,H>, hash: H, k: K)
        -> Entry<'a, K, V>
Re:Redis re-implemented in Rust by Jweb_Guru on Friday June 19, 2015 @11:10AM (#9745302)
RawTable doesn't have to be because the hash function has already been computed at that point. The actual hash table is.
Re:Redis re-implemented in Rust by Jweb_Guru on Friday June 19, 2015 @09:08AM (#9744390)
It could be inferred in some languages (notably MLs).
Re:Redis re-implemented in Rust by pygy_ on Friday June 19, 2015 @03:30PM (#9747100)
Including parametrization?
Re:Redis re-implemented in Rust by Jweb_Guru on Saturday June 20, 2015 @12:54AM (#9749038)
Yes.
Re:Redis re-implemented in Rust by pornel on Friday June 19, 2015 @09:40AM (#9744604)
In Rust it's unfortunately typical to give one-letter names to generic types. A verbose version could be:

   fn search_entry_hashed<'lifetime, KeyType: Eq, ValueType>
      (table: &'lifetime mut RawTable<KeyType, ValueType>, hash: SafeHash, key: KeyType)
      -> Entry<'lifetime, KeyType, ValueType>
Re:Redis re-implemented in Rust by Jweb_Guru on Friday June 19, 2015 @11:14AM (#9745333)
"'lifetime" gives no useful semantic information there. All 'somethings are lifetimes; it would be like naming a type parameter "Type," or a variable "variable." If you don't have a specific shard context that would give the name meaning, `'a` is as good as any. I do agree that something like Key or Value would probably be better than K or V.
Re:Redis re-implemented in Rust by nemaar on Friday June 19, 2015 @12:45PM (#9746024)
Yes, in general, it is a good idea to give more descriptive names but in the context of a hashtable, K and V are good enough. I seriously doubt that there is anyone reading the source code of a hashtable and cannot figure out in milliseconds what K and V mean (how fast is the human brain?:).
Re:Redis re-implemented in Rust by rmc on Friday June 19, 2015 @08:43AM (#9744282)
Depends if you know Rust. The language can do things with types and memory that (say) something like Python or Ruby don't do, which means Rust needs extra syntax to mark those things. Most of the <> or ' are to do with types or memory safety.
Re:Redis re-implemented in Rust by yaongi on Friday June 19, 2015 @06:29AM (#9743909)
It's alright.