{"action":"created","comment":{"url":"https://api.github.com/repos/milessabin/shapeless/pulls/comments/36546618","id":36546618,"diff_hunk":"@@ -46,48 +47,187 @@ object Lazy {\n   def values[T <: HList](implicit lv: Lazy[Values[T]]): T = lv.value.values\n \n   implicit def mkLazy[I]: Lazy[I] = macro LazyMacros.mkLazyImpl[I]\n+\n+  trait Cached[+T] extends Lazy[T] {\n+    override def map[U](f: T => U): Cached[U] = Cached { f(value) }\n+    def flatMap[U](f: T => Cached[U]): Cached[U] = Cached { f(value).value }\n+  }\n+\n+  object Cached {\n+    implicit def apply[T](t: => T): Cached[T] =\n+      new Cached[T] {\n+        val value = t\n+      }\n+\n+    def unapply[T](lt: Cached[T]): Option[T] = Some(lt.value)\n+\n+    implicit def mkCached[I]: Cached[I] = macro LazyMacros.mkCachedLazyImpl[I]\n+  }\n+\n }\n \n object lazily {\n   def apply[T](implicit lv: Lazy[T]): T = lv.value\n }\n \n+trait Strict[+T] extends Serializable {","path":"core/src/main/scala/shapeless/lazy.scala","position":35,"original_position":35,"commit_id":"d1d6ca1162ed56e8c9ce296f2fd9a7e35f4eb28a","original_commit_id":"78ea00b464e483cb980e1eea55267ade9218a72e","user":{"login":"alexarchambault","id":7063723,"avatar_url":"https://avatars.githubusercontent.com/u/7063723?v=3","gravatar_id":"","url":"https://api.github.com/users/alexarchambault","html_url":"https://github.com/alexarchambault","followers_url":"https://api.github.com/users/alexarchambault/followers","following_url":"https://api.github.com/users/alexarchambault/following{/other_user}","gists_url":"https://api.github.com/users/alexarchambault/gists{/gist_id}","starred_url":"https://api.github.com/users/alexarchambault/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexarchambault/subscriptions","organizations_url":"https://api.github.com/users/alexarchambault/orgs","repos_url":"https://api.github.com/users/alexarchambault/repos","events_url":"https://api.github.com/users/alexarchambault/events{/privacy}","received_events_url":"https://api.github.com/users/alexarchambault/received_events","type":"User","site_admin":false},"body":"In my tests, I cut it in the `genericTC` implicit argument for the `TC` of an hlist, `TC[List[CC] :: HNil]` here, so not the \"root\". As long as the cycle is cut at one point, no matter which one, it should be safe. No need to enforce additional constraints. (Unless I'm missing something here, which I don't think I do.)","created_at":"2015-08-07T18:24:42Z","updated_at":"2015-08-07T18:24:42Z","html_url":"https://github.com/milessabin/shapeless/pull/435#discussion_r36546618","pull_request_url":"https://api.github.com/repos/milessabin/shapeless/pulls/435","_links":{"self":{"href":"https://api.github.com/repos/milessabin/shapeless/pulls/comments/36546618"},"html":{"href":"https://github.com/milessabin/shapeless/pull/435#discussion_r36546618"},"pull_request":{"href":"https://api.github.com/repos/milessabin/shapeless/pulls/435"}}},"pull_request":{"url":"https://api.github.com/repos/milessabin/shapeless/pulls/435","id":40903160,"html_url":"https://github.com/milessabin/shapeless/pull/435","diff_url":"https://github.com/milessabin/shapeless/pull/435.diff","patch_url":"https://github.com/milessabin/shapeless/pull/435.patch","issue_url":"https://api.github.com/repos/milessabin/shapeless/issues/435","number":435,"state":"open","locked":false,"title":"Lazy extensions","user":{"login":"alexarchambault","id":7063723,"avatar_url":"https://avatars.githubusercontent.com/u/7063723?v=3","gravatar_id":"","url":"https://api.github.com/users/alexarchambault","html_url":"https://github.com/alexarchambault","followers_url":"https://api.github.com/users/alexarchambault/followers","following_url":"https://api.github.com/users/alexarchambault/following{/other_user}","gists_url":"https://api.github.com/users/alexarchambault/gists{/gist_id}","starred_url":"https://api.github.com/users/alexarchambault/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexarchambault/subscriptions","organizations_url":"https://api.github.com/users/alexarchambault/orgs","repos_url":"https://api.github.com/users/alexarchambault/repos","events_url":"https://api.github.com/users/alexarchambault/events{/privacy}","received_events_url":"https://api.github.com/users/alexarchambault/received_events","type":"User","site_admin":false},"body":"Opening this to discuss the developments in the [lazyextensions branch](https://github.com/milessabin/shapeless/tree/topic/lazyextensions).\r\n\r\nIt adds:\r\n- a `Strict` type class, that circumvents implicit divergences like `Lazy`, without the overhead of an anonymous function when instantiated (hence an extra class),\r\n- the possibility to extend `Lazy` with extensions, able to change the current derivation and its state, and keep their own state along with it,\r\n- a `Priority` type class and a Lazy extension, to be used wrapped in an implicit `Strict` or `Lazy`, like\r\n```scala\r\nimplicit def mkTC[T]\r\n (implicit\r\n   priority: Strict[Priority[TC[T], Other[T]]]\r\n ): TC[T] = priority.value.fold(identity)(_.mkTC)\r\n```\r\nwhich looks up for a `TC[T]`, else for a `Other[T]`, taking into account that a `TC[T]` is also provided through itself (and ignoring it in the first `TC[T]` lookup - thus looking for orphan `TC[T]` only),\r\n- various inlining of implicits in the `Strict` and `Lazy` output, for less overhead (see https://github.com/milessabin/shapeless/commit/1add5ffd55a7b04aef23022a9bd5089ed694436d).\r\n\r\nAlso things that proved not to be useful, that I'd like to remove carefully, like\r\n- some changes in `Generic`,\r\n- using the state monad to manage the derivation state,\r\n- keep track of implicit lookup that failed, not to look them once more,\r\n- a lazy extension called `Scoped`, that keeps the implicit dict from a lookup to the next (-> more caching).\r\n\r\nI'm somehow benchmarking this versus the macro-based derivation of [upickle](https://github.com/lihaoyi/upickle-pprint), with [a modified version of it](https://github.com/alexarchambault/upickle-pprint). The better I get is a bit less than a 3 times longer compile time for its tests :-( (from initially... much more than that).","created_at":"2015-07-27T13:30:46Z","updated_at":"2015-08-07T18:24:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"255c3e5e595ad6ff9fa9c97e31646ec4844487f8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/milessabin/shapeless/pulls/435/commits","review_comments_url":"https://api.github.com/repos/milessabin/shapeless/pulls/435/comments","review_comment_url":"https://api.github.com/repos/milessabin/shapeless/pulls/comments{/number}","comments_url":"https://api.github.com/repos/milessabin/shapeless/issues/435/comments","statuses_url":"https://api.github.com/repos/milessabin/shapeless/statuses/d1d6ca1162ed56e8c9ce296f2fd9a7e35f4eb28a","head":{"label":"milessabin:topic/lazyextensions","ref":"topic/lazyextensions","sha":"d1d6ca1162ed56e8c9ce296f2fd9a7e35f4eb28a","user":{"login":"milessabin","id":131183,"avatar_url":"https://avatars.githubusercontent.com/u/131183?v=3","gravatar_id":"","url":"https://api.github.com/users/milessabin","html_url":"https://github.com/milessabin","followers_url":"https://api.github.com/users/milessabin/followers","following_url":"https://api.github.com/users/milessabin/following{/other_user}","gists_url":"https://api.github.com/users/milessabin/gists{/gist_id}","starred_url":"https://api.github.com/users/milessabin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milessabin/subscriptions","organizations_url":"https://api.github.com/users/milessabin/orgs","repos_url":"https://api.github.com/users/milessabin/repos","events_url":"https://api.github.com/users/milessabin/events{/privacy}","received_events_url":"https://api.github.com/users/milessabin/received_events","type":"User","site_admin":false},"repo":{"id":3006066,"name":"shapeless","full_name":"milessabin/shapeless","owner":{"login":"milessabin","id":131183,"avatar_url":"https://avatars.githubusercontent.com/u/131183?v=3","gravatar_id":"","url":"https://api.github.com/users/milessabin","html_url":"https://github.com/milessabin","followers_url":"https://api.github.com/users/milessabin/followers","following_url":"https://api.github.com/users/milessabin/following{/other_user}","gists_url":"https://api.github.com/users/milessabin/gists{/gist_id}","starred_url":"https://api.github.com/users/milessabin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milessabin/subscriptions","organizations_url":"https://api.github.com/users/milessabin/orgs","repos_url":"https://api.github.com/users/milessabin/repos","events_url":"https://api.github.com/users/milessabin/events{/privacy}","received_events_url":"https://api.github.com/users/milessabin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/milessabin/shapeless","description":"Generic programming for Scala","fork":false,"url":"https://api.github.com/repos/milessabin/shapeless","forks_url":"https://api.github.com/repos/milessabin/shapeless/forks","keys_url":"https://api.github.com/repos/milessabin/shapeless/keys{/key_id}","collaborators_url":"https://api.github.com/repos/milessabin/shapeless/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/milessabin/shapeless/teams","hooks_url":"https://api.github.com/repos/milessabin/shapeless/hooks","issue_events_url":"https://api.github.com/repos/milessabin/shapeless/issues/events{/number}","events_url":"https://api.github.com/repos/milessabin/shapeless/events","assignees_url":"https://api.github.com/repos/milessabin/shapeless/assignees{/user}","branches_url":"https://api.github.com/repos/milessabin/shapeless/branches{/branch}","tags_url":"https://api.github.com/repos/milessabin/shapeless/tags","blobs_url":"https://api.github.com/repos/milessabin/shapeless/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/milessabin/shapeless/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/milessabin/shapeless/git/refs{/sha}","trees_url":"https://api.github.com/repos/milessabin/shapeless/git/trees{/sha}","statuses_url":"https://api.github.com/repos/milessabin/shapeless/statuses/{sha}","languages_url":"https://api.github.com/repos/milessabin/shapeless/languages","stargazers_url":"https://api.github.com/repos/milessabin/shapeless/stargazers","contributors_url":"https://api.github.com/repos/milessabin/shapeless/contributors","subscribers_url":"https://api.github.com/repos/milessabin/shapeless/subscribers","subscription_url":"https://api.github.com/repos/milessabin/shapeless/subscription","commits_url":"https://api.github.com/repos/milessabin/shapeless/commits{/sha}","git_commits_url":"https://api.github.com/repos/milessabin/shapeless/git/commits{/sha}","comments_url":"https://api.github.com/repos/milessabin/shapeless/comments{/number}","issue_comment_url":"https://api.github.com/repos/milessabin/shapeless/issues/comments{/number}","contents_url":"https://api.github.com/repos/milessabin/shapeless/contents/{+path}","compare_url":"https://api.github.com/repos/milessabin/shapeless/compare/{base}...{head}","merges_url":"https://api.github.com/repos/milessabin/shapeless/merges","archive_url":"https://api.github.com/repos/milessabin/shapeless/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/milessabin/shapeless/downloads","issues_url":"https://api.github.com/repos/milessabin/shapeless/issues{/number}","pulls_url":"https://api.github.com/repos/milessabin/shapeless/pulls{/number}","milestones_url":"https://api.github.com/repos/milessabin/shapeless/milestones{/number}","notifications_url":"https://api.github.com/repos/milessabin/shapeless/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/milessabin/shapeless/labels{/name}","releases_url":"https://api.github.com/repos/milessabin/shapeless/releases{/id}","created_at":"2011-12-18T13:36:38Z","updated_at":"2015-08-07T01:57:57Z","pushed_at":"2015-08-07T18:18:10Z","git_url":"git://github.com/milessabin/shapeless.git","ssh_url":"git@github.com:milessabin/shapeless.git","clone_url":"https://github.com/milessabin/shapeless.git","svn_url":"https://github.com/milessabin/shapeless","homepage":"","size":8121,"stargazers_count":1172,"watchers_count":1172,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":179,"mirror_url":null,"open_issues_count":75,"forks":179,"open_issues":75,"watchers":1172,"default_branch":"master"}},"base":{"label":"milessabin:master","ref":"master","sha":"bbbda320e76dfb6a75a2d67217810812b6e9d0b7","user":{"login":"milessabin","id":131183,"avatar_url":"https://avatars.githubusercontent.com/u/131183?v=3","gravatar_id":"","url":"https://api.github.com/users/milessabin","html_url":"https://github.com/milessabin","followers_url":"https://api.github.com/users/milessabin/followers","following_url":"https://api.github.com/users/milessabin/following{/other_user}","gists_url":"https://api.github.com/users/milessabin/gists{/gist_id}","starred_url":"https://api.github.com/users/milessabin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milessabin/subscriptions","organizations_url":"https://api.github.com/users/milessabin/orgs","repos_url":"https://api.github.com/users/milessabin/repos","events_url":"https://api.github.com/users/milessabin/events{/privacy}","received_events_url":"https://api.github.com/users/milessabin/received_events","type":"User","site_admin":false},"repo":{"id":3006066,"name":"shapeless","full_name":"milessabin/shapeless","owner":{"login":"milessabin","id":131183,"avatar_url":"https://avatars.githubusercontent.com/u/131183?v=3","gravatar_id":"","url":"https://api.github.com/users/milessabin","html_url":"https://github.com/milessabin","followers_url":"https://api.github.com/users/milessabin/followers","following_url":"https://api.github.com/users/milessabin/following{/other_user}","gists_url":"https://api.github.com/users/milessabin/gists{/gist_id}","starred_url":"https://api.github.com/users/milessabin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milessabin/subscriptions","organizations_url":"https://api.github.com/users/milessabin/orgs","repos_url":"https://api.github.com/users/milessabin/repos","events_url":"https://api.github.com/users/milessabin/events{/privacy}","received_events_url":"https://api.github.com/users/milessabin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/milessabin/shapeless","description":"Generic programming for Scala","fork":false,"url":"https://api.github.com/repos/milessabin/shapeless","forks_url":"https://api.github.com/repos/milessabin/shapeless/forks","keys_url":"https://api.github.com/repos/milessabin/shapeless/keys{/key_id}","collaborators_url":"https://api.github.com/repos/milessabin/shapeless/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/milessabin/shapeless/teams","hooks_url":"https://api.github.com/repos/milessabin/shapeless/hooks","issue_events_url":"https://api.github.com/repos/milessabin/shapeless/issues/events{/number}","events_url":"https://api.github.com/repos/milessabin/shapeless/events","assignees_url":"https://api.github.com/repos/milessabin/shapeless/assignees{/user}","branches_url":"https://api.github.com/repos/milessabin/shapeless/branches{/branch}","tags_url":"https://api.github.com/repos/milessabin/shapeless/tags","blobs_url":"https://api.github.com/repos/milessabin/shapeless/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/milessabin/shapeless/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/milessabin/shapeless/git/refs{/sha}","trees_url":"https://api.github.com/repos/milessabin/shapeless/git/trees{/sha}","statuses_url":"https://api.github.com/repos/milessabin/shapeless/statuses/{sha}","languages_url":"https://api.github.com/repos/milessabin/shapeless/languages","stargazers_url":"https://api.github.com/repos/milessabin/shapeless/stargazers","contributors_url":"https://api.github.com/repos/milessabin/shapeless/contributors","subscribers_url":"https://api.github.com/repos/milessabin/shapeless/subscribers","subscription_url":"https://api.github.com/repos/milessabin/shapeless/subscription","commits_url":"https://api.github.com/repos/milessabin/shapeless/commits{/sha}","git_commits_url":"https://api.github.com/repos/milessabin/shapeless/git/commits{/sha}","comments_url":"https://api.github.com/repos/milessabin/shapeless/comments{/number}","issue_comment_url":"https://api.github.com/repos/milessabin/shapeless/issues/comments{/number}","contents_url":"https://api.github.com/repos/milessabin/shapeless/contents/{+path}","compare_url":"https://api.github.com/repos/milessabin/shapeless/compare/{base}...{head}","merges_url":"https://api.github.com/repos/milessabin/shapeless/merges","archive_url":"https://api.github.com/repos/milessabin/shapeless/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/milessabin/shapeless/downloads","issues_url":"https://api.github.com/repos/milessabin/shapeless/issues{/number}","pulls_url":"https://api.github.com/repos/milessabin/shapeless/pulls{/number}","milestones_url":"https://api.github.com/repos/milessabin/shapeless/milestones{/number}","notifications_url":"https://api.github.com/repos/milessabin/shapeless/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/milessabin/shapeless/labels{/name}","releases_url":"https://api.github.com/repos/milessabin/shapeless/releases{/id}","created_at":"2011-12-18T13:36:38Z","updated_at":"2015-08-07T01:57:57Z","pushed_at":"2015-08-07T18:18:10Z","git_url":"git://github.com/milessabin/shapeless.git","ssh_url":"git@github.com:milessabin/shapeless.git","clone_url":"https://github.com/milessabin/shapeless.git","svn_url":"https://github.com/milessabin/shapeless","homepage":"","size":8121,"stargazers_count":1172,"watchers_count":1172,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":179,"mirror_url":null,"open_issues_count":75,"forks":179,"open_issues":75,"watchers":1172,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/milessabin/shapeless/pulls/435"},"html":{"href":"https://github.com/milessabin/shapeless/pull/435"},"issue":{"href":"https://api.github.com/repos/milessabin/shapeless/issues/435"},"comments":{"href":"https://api.github.com/repos/milessabin/shapeless/issues/435/comments"},"review_comments":{"href":"https://api.github.com/repos/milessabin/shapeless/pulls/435/comments"},"review_comment":{"href":"https://api.github.com/repos/milessabin/shapeless/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/milessabin/shapeless/pulls/435/commits"},"statuses":{"href":"https://api.github.com/repos/milessabin/shapeless/statuses/d1d6ca1162ed56e8c9ce296f2fd9a7e35f4eb28a"}}}}