{"id":1002054,"date":"2009-01-24T10:31:07","date_gmt":"2009-01-24T15:31:07","guid":{"rendered":"http:\/\/www.elharo.com\/blog\/?p=1002054"},"modified":"2009-01-24T10:31:07","modified_gmt":"2009-01-24T15:31:07","slug":"hypothesis-cycles-cannot-be-implemented-only-with-folds","status":"publish","type":"post","link":"https:\/\/www.elharo.com\/blog\/software-development\/haskell\/2009\/01\/24\/hypothesis-cycles-cannot-be-implemented-only-with-folds\/","title":{"rendered":"Hypothesis: cycles cannot be implemented only with folds"},"content":{"rendered":"<p>The <code>cycle<\/code> function turns a list into an infinite list by repeating it. For instance, <code>cycle [1,2,3]<\/code> is <code>[1,2,3,1,2,3,1,2,3...]<\/code>. I could be wrong but I don&#8217;t think you can do this one purely with folds and here&#8217;s why:<br \/>\n<!--more--><\/p>\n<ol>\n<li>The infinite list would have to be the accumulator.<\/li>\n<li>A fold (foldr or foldl) operation steps over (processes) each element of the finite input list exactly once.<\/li>\n<li>Each step can insert only a finite number of elements into the accumulator list.<\/li>\n<li>Thus the final accumulated list must be finite.<\/li>\n<\/ol>\n<p>Of course, Murphy&#8217;s Law guarantees that someone is now going to post a cycle implementation with pure folds in the comments. If there&#8217;s a mistake in this proof, it&#8217;s in step 3. But it really feels to me like a fold alone won&#8217;t do the trick. You have to use recursion of some sort here. Maybe a fold of folds? What if the step function is itself a fold? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The cycle function turns a list into an infinite list by repeating it. For instance, cycle [1,2,3] is [1,2,3,1,2,3,1,2,3&#8230;]. I could be wrong but I don&#8217;t think you can do this one purely with folds and here&#8217;s why:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[],"class_list":["post-1002054","post","type-post","status-publish","format-standard","hentry","category-haskell"],"_links":{"self":[{"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/posts\/1002054","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/comments?post=1002054"}],"version-history":[{"count":5,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/posts\/1002054\/revisions"}],"predecessor-version":[{"id":1002065,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/posts\/1002054\/revisions\/1002065"}],"wp:attachment":[{"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/media?parent=1002054"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/categories?post=1002054"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elharo.com\/blog\/wp-json\/wp\/v2\/tags?post=1002054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}