The Artima Developer Community
Sponsored Link

Java Buzz Forum
Hypothesis: cycles cannot be implemented only with folds

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Elliotte Rusty Harold

Posts: 1573
Nickname: elharo
Registered: Apr, 2003

Elliotte Rusty Harold is an author, developer, and general kibitzer.
Hypothesis: cycles cannot be implemented only with folds Posted: Jan 24, 2009 9:38 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Elliotte Rusty Harold.
Original Post: Hypothesis: cycles cannot be implemented only with folds
Feed Title: Mokka mit Schlag
Feed URL: http://www.elharo.com/blog/feed/atom/?
Feed Description: Ranting and Raving
Latest Java Buzz Posts
Latest Java Buzz Posts by Elliotte Rusty Harold
Latest Posts From Mokka mit Schlag

Advertisement

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...]. I could be wrong but I don’t think you can do this one purely with folds and here’s why:

  1. The infinite list would have to be the accumulator.
  2. A fold (foldr or foldl) operation steps over (processes) each element of the finite input list exactly once.
  3. Each step can insert only a finite number of elements into the accumulator list.
  4. Thus the final accumulated list must be finite.

Of course, Murphy’s Law guarantees that someone is now going to post a cycle implementation with pure folds in the comments. If there’s a mistake in this proof, it’s in step 3. But it really feels to me like a fold alone won’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?

Read: Hypothesis: cycles cannot be implemented only with folds

Topic: Blue Monday Previous Topic   Next Topic Topic: How to Achieve Windows Vista-Style Taskbar in Windows 7 in Two Simple Steps

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use