|
Re: Another nit: msg#00511lang.scala
Tony Morris <tmorris@xxxxxxxxxxx> writes: > > By existing APIs, do you include scala.Stream, by the way? The name > > scala.Stream makes it hard to find for people who are looking for > > "Lazy List". > > Yes, I have seen scala.Stream, but it took Martin to point it out to me > for the reasons that you mention. I don't like the fact that its type > parameter is invariant, nor the fact that it is a trait. Actually, it is covariant. We need to fix the API docs to make this clearer. Notice, for example, that "Stream.empty" is actually a singleton value of type Stream[Nothing]. This works due to the covariance. On the other question, why does it matter if it's a trait? > >> MyList[A] <-> scala.List[A] > >> MyList[A] <-> scala.Stream[A] > >> MyList[A] <-> scala.Iterator[A] > > > > These are generally cool, but this third one looks weird to me. Scala > > carefully distinguishes Iterable's from Iterator's. If you want an > > iterator, you send elements. > > I don't understand your point here; an Iterator *is* a lazy list, just > in the imperative model - I had to write imperative code with a > destructive update (cough, choke) in that method. I'm interested in > understanding your point here. My point is that in Scala, you can access a collection both ways: destructive once-only iteration (Iterator), and non-destructively (Iterable). You start with an Iterable, and if you want the destructive mode then you explicitly call "elements". Maybe the library should be arranged differently, but that is how things are set up right now. > >> But then you can get really funky within a mixin. How about the ordering > >> relationship? > >> trait Ord[A] extends Equal[A] { > > > > This one is in the library, by the way. Great minds think alike. :) > > Where is it? scala.Ordered . You define a compare method and then get the other orderings automatically (<, <=, >, >=). def compare (that: a): Int You do not get equals(), because the trait does not know how to define hashCode(). If you use this, you'll probably also want to override hashCode() and equals(). -Lex |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Another nit: 00511, Tony Morris |
|---|---|
| Next by Date: | Re: How do I use DTD's with Scala 2.3.0's XML object literals?: 00511, Burak Emir |
| Previous by Thread: | Re: Another niti: 00511, Tony Morris |
| Next by Thread: | RE: Another nit: 00511, Ted Neward |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |