Thanks for the info! Sized will be going away very soon, but it will be replaced by 'unsized' (or something with the same semantics), so we have exactly the same question.
I don't understand the HashMap example (I'm thinking in Rust terms, and perhaps you meant it to be a Haskell example, I'm not sure). But if we have a HashMap<T> struct, I would expect T to be hashable - I can't construct a HashMap<T> if it is not, so there is nothing to call is_empty or size on. I suppose you could allow empty HashMaps of such types, but that seems unnecessary. Cheers, Nick On Wed, Mar 26, 2014 at 6:32 AM, Matthieu Monrocq < matthieu.monr...@gmail.com> wrote: > > > > On Tue, Mar 25, 2014 at 6:00 PM, Patrick Walton <pcwal...@mozilla.com>wrote: > >> On 3/24/14 11:46 PM, Nick Cameron wrote: >> >>> Currently we forbid bounds on type parameters in structs, enums, and >>> types. So the following is illegal: >>> >>> struct S<X: B> { >>> f: ~T<X>, >>> } >>> >> >> IIRC Haskell allows bounds on type parameters (and we did once too), but >> I heard that considered deprecated and not preferred. I don't recall the >> exact reasons, but that's why we removed the feature (and also just for >> language simplicity). >> >> Patrick >> >> > If I remember the reason cited in Haskell design it was that some > functions require more bounds than others. > > For example a HashMap generally requires that the key be hashable somehow, > but the "isEmpty" or "size" functions on a HashMap have no such requirement. > > Therefore, you would end up with a "minimal" bounds precised at Type > level, and then each function could add some more bounds depending on their > needs: that's 2 places to specify bounds. In the name of simplicity (and > maximum reusability of types) Haskell therefore advise to only use bounds > on functions. > > > However, I seem to remember than in Haskell the bounds are only Traits; > whereas in Rust some bounds may actually be required to be able to > instantiate the type (Sized ?). > > -- Matthieu > > > >> _______________________________________________ >> Rust-dev mailing list >> Rust-dev@mozilla.org >> https://mail.mozilla.org/listinfo/rust-dev >> > > > _______________________________________________ > Rust-dev mailing list > Rust-dev@mozilla.org > https://mail.mozilla.org/listinfo/rust-dev > >
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev