parameters to traits in collection library.

25 views
Skip to first unread message

G J

unread,
Mar 18, 2013, 8:55:50 AM3/18/13
to scala...@googlegroups.com

I embarrassed to say that I have been using Scala for some time, but I find one cornerstone hard to understand - among others. It's the type parameters used in much of the collection library. Is there a pointer that explains this? Specifically:


    trait IndexedSeq[+A]                                                                                        (1)

           extends Seq[A] with GenericTraversableTemplate[A, IndexedSeq]            (2)

                with IndexedSeqLike[A, IndexedSeq[A]]                                               (3)


  • On (2): why is it IndexedSeq and not IndexedSeq[A]; I mean, what is IndexedSeq on its own anyway.
  • On (3) we are defining IndexedSeq[+A] in terms of IndexedSeq[A].  I don't understand the recursion here.
  • On (3) that type  parameter is supposed to be the underlying representation for IndexedSeq[A]. Declaring it the way shown appears to be circular.

Thanks.

Best Regards.



Axel Poigné

unread,
Mar 18, 2013, 9:30:16 AM3/18/13
to G J, scala...@googlegroups.com

Sonnenschein

unread,
Mar 18, 2013, 11:16:24 AM3/18/13
to scala...@googlegroups.com
  • On (2): why is it IndexedSeq and not IndexedSeq[A]; I mean, what is IndexedSeq on its own anyway.
  • On (3) that type  parameter is supposed to be the underlying representation for IndexedSeq[A]. Declaring it the way shown appears to be circular.
Circular dependencies would be detected by the compiler as error.
Reply all
Reply to author
Forward
0 new messages