tag:blogger.com,1999:blog-7317245822288637185.post5912603166517718177..comments2023-03-28T10:19:42.467-07:00Comments on Graham Hacking Scala: Scala Pragmatism: Ignore CanBuildFromGraham Leahttp://www.blogger.com/profile/07862939329898536954noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-7317245822288637185.post-91300447715540306542011-01-18T17:55:53.925-08:002011-01-18T17:55:53.925-08:00@martin: Thanks very much for your compliment, and...@martin: Thanks very much for your compliment, and even more so for solving the final mystery. I never knew that implicit resolution extended to companion objects, so that's a nice little nugget.<br /><br />Your explanation that it searches companion objects for "some part of T" is interesting in its lack of specificity. When you say "some part", it seems you are saying that the compiler flattens out the required type and its parameters. Is that right? So if the type of some more restrictive implicit parameter were<br />CanBuildFrom[List[Lead], (Lead,Gold), ?]<br />then would it flatten that type out to:<br />CanBuildFrom, List, Lead, Gold <br />and then search any companion objects of all four of those?<br /><br />Cheers,<br /><br />Graham.Grazerhttps://www.blogger.com/profile/00435359638152521056noreply@blogger.comtag:blogger.com,1999:blog-7317245822288637185.post-92103125852240740112011-01-18T17:19:04.513-08:002011-01-18T17:19:04.513-08:00@Eric P: Thanks very much for those links.
The ...@Eric P: Thanks very much for those links.<br />The 'collections-impl' pages on scala-lang in particular look like they give a much more practically-minded description of the underlying magic than Adrian's paper. (That's not a criticism of the paper, of course - it's for a different audience.) I think I'll add that one into the post.Grazerhttps://www.blogger.com/profile/00435359638152521056noreply@blogger.comtag:blogger.com,1999:blog-7317245822288637185.post-60130039213598348762011-01-18T09:01:56.910-08:002011-01-18T09:01:56.910-08:00Very good explanation, Graham! To answer your ques...Very good explanation, Graham! To answer your question at the end: If the compiler searches for an implicit parameter with type T, it will first consider all implicits in scope. If none is found, it will next consider all implicits that are contained in a companion object of some part of T. <br /><br />In the concrete case you mention, you are looking for an implicit value of type<br /><br /> CanBuildFrom[List[A], (A, B), ?]<br /><br />where the ? can be any type. List is a part of this type, so the compiler will look up the implicit canBuildFrom in its companion object. And that's how it is found.<br /><br />But I want to really stress here that the user of the collection library does not need to know anything about all this - it just works. As you write, concentrate on the [use case] defs and you are fine.martinhttps://www.blogger.com/profile/05955349008001468964noreply@blogger.comtag:blogger.com,1999:blog-7317245822288637185.post-49203967341411271942011-01-18T06:24:17.244-08:002011-01-18T06:24:17.244-08:00Hi Graham - check out
http://www.scala-lang.org/d...Hi Graham - check out <br />http://www.scala-lang.org/docu/files/collections-api/collections-impl.html and also<br />http://lampwww.epfl.ch/~odersky/papers/fsttcs2009.pdf.<br /><br />Both go into detail regarding the design of the 2.8 collections APIEric Phttps://www.blogger.com/profile/01588189056604414087noreply@blogger.com