[rust-dev] Bikeshed impl method extraction

Gareth Smith garethdanielsmith at gmail.com
Mon Apr 30 11:35:31 PDT 2012

On 30/04/12 07:08, Steven Blenkinsop wrote:
> On Sunday, April 29, 2012, Gareth Smith wrote:
>     Hi,
>     I have written up some thoughts about a enabling a less
>     repetitious API for constructing hashmaps (amongst other
>     possibilities), here:
>     https://github.com/mozilla/rust/wiki/Bikeshed-impl-method-extraction
>     Does this make any sense?
> Couldn't you just do something like:
> fn hashmap <K:hash equals copy, V:copy> () -> std::map::hashmap<K, V> {
>     ret std::map::hashmap({|k| k.hash()}, {|k1,k2| k1.equals(k2)});
> }
> ?
Ah, I had not considered that - and it looks to me like it should work - 
but it doesn't:

hello.rs:26:31: 26:37 error: the type of this value must be known in 
this context
hello.rs:26     ret std::map::hashmap({|k| k.hash()}, {|k1, k2| 

but this might be a type inference bug, because if it is rewritten with 
type annotations then it works:

let hashfn:fn@(K)->uint = {|k| k.hash()};
let eqfn:fn@(K, K)->bool = {|a, b| a.equals(b)};
ret std::map::hashmap(hashfn, eqfn);

Considering your answer, and the other answers, I have abandoned this 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20120430/97fe9052/attachment.html>

More information about the Rust-dev mailing list