{"action":"created","issue":{"url":"https://api.github.com/repos/haskell/cabal/issues/2962","labels_url":"https://api.github.com/repos/haskell/cabal/issues/2962/labels{/name}","comments_url":"https://api.github.com/repos/haskell/cabal/issues/2962/comments","events_url":"https://api.github.com/repos/haskell/cabal/issues/2962/events","html_url":"https://github.com/haskell/cabal/pull/2962","id":122908160,"number":2962,"title":"Separate out reading index from building cache","user":{"login":"edsko","id":935288,"avatar_url":"https://avatars.githubusercontent.com/u/935288?v=3","gravatar_id":"","url":"https://api.github.com/users/edsko","html_url":"https://github.com/edsko","followers_url":"https://api.github.com/users/edsko/followers","following_url":"https://api.github.com/users/edsko/following{/other_user}","gists_url":"https://api.github.com/users/edsko/gists{/gist_id}","starred_url":"https://api.github.com/users/edsko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edsko/subscriptions","organizations_url":"https://api.github.com/users/edsko/orgs","repos_url":"https://api.github.com/users/edsko/repos","events_url":"https://api.github.com/users/edsko/events{/privacy}","received_events_url":"https://api.github.com/users/edsko/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-18T09:02:36Z","updated_at":"2015-12-18T21:44:05Z","closed_at":"2015-12-18T21:43:58Z","pull_request":{"url":"https://api.github.com/repos/haskell/cabal/pulls/2962","html_url":"https://github.com/haskell/cabal/pull/2962","diff_url":"https://github.com/haskell/cabal/pull/2962.diff","patch_url":"https://github.com/haskell/cabal/pull/2962.patch"},"body":"The cache construction was using lazy I/O to avoid building the cache in memory all at once, but I found the algorithm a little hard to follow. This commit makes a few changes; they don't change anything fundamental, just make it a bit easier to follow:\r\n\r\n* Separated out\r\n\r\n    ``` haskell\r\n    tarEntriesList :: Tar.Entries -> [(BlockNo, Tar.Entry)]\r\n    ```\r\n\r\n  into its own function. This now makes the top-level of `parsePackageIndex` a straight-forward composition\r\n\r\n    ``` haskell\r\n    concatMap (uncurry extract) . tarEntriesList . Tar.read\r\n    ```\r\n \r\n  so that it's easier to see that this indeed as lazy as we want. (Previously especially the name \"accum\" suggests an accumulator and hence a foldl rather than a foldr style, which would not be good; that bit of the algorithm is now the separate `tarEntriesList` function.)\r\n\r\n* Changed the definition of `lazySequence` to avoid the unnecessary nested use of `unsafeInterleaveIO`; a single one suffices:\r\n\r\n    ``` haskell\r\n    lazySequence :: [IO a] -> IO [a]\r\n    lazySequence = unsafeInterleaveIO . go\r\n      where\r\n        go []     = return []\r\n        go (x:xs) = do x'  <- x\r\n                       xs' <- lazySequence xs\r\n                       return (x' : xs')\r\n    ```\r\n\r\n* Introduced `withIndexEntries`, which makes it very clear in which scope we can, and must, consume the lazy list we get from all this. "},"comment":{"url":"https://api.github.com/repos/haskell/cabal/issues/comments/165904068","html_url":"https://github.com/haskell/cabal/pull/2962#issuecomment-165904068","issue_url":"https://api.github.com/repos/haskell/cabal/issues/2962","id":165904068,"user":{"login":"23Skidoo","id":47439,"avatar_url":"https://avatars.githubusercontent.com/u/47439?v=3","gravatar_id":"","url":"https://api.github.com/users/23Skidoo","html_url":"https://github.com/23Skidoo","followers_url":"https://api.github.com/users/23Skidoo/followers","following_url":"https://api.github.com/users/23Skidoo/following{/other_user}","gists_url":"https://api.github.com/users/23Skidoo/gists{/gist_id}","starred_url":"https://api.github.com/users/23Skidoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/23Skidoo/subscriptions","organizations_url":"https://api.github.com/users/23Skidoo/orgs","repos_url":"https://api.github.com/users/23Skidoo/repos","events_url":"https://api.github.com/users/23Skidoo/events{/privacy}","received_events_url":"https://api.github.com/users/23Skidoo/received_events","type":"User","site_admin":false},"created_at":"2015-12-18T21:44:05Z","updated_at":"2015-12-18T21:44:05Z","body":"Merged, thanks!"}}