Timeline for How does "repeat x = x:repeat x" return a list in Haskell?
Current License: CC BY-SA 3.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 3, 2017 at 15:08 | comment | added | Reinstate Monica |
Note that Haskell's equivalent of amon's construction is actually repeat' x = let xs = x : xs in xs. The subtle difference is that this implementation creates one self-referential node because the recursion is in the data, whereas the code in the question actually creates a (lazy) infinite list because the recursion is in the function call.
|
|
| Dec 17, 2015 at 1:51 | answer | added | sacundim | timeline score: 0 | |
| S Dec 2, 2015 at 9:38 | history | suggested | Garg | CC BY-SA 3.0 |
improved formatting
|
| Dec 2, 2015 at 6:07 | review | Suggested edits | |||
| S Dec 2, 2015 at 9:38 | |||||
| Dec 1, 2015 at 20:48 | answer | added | Ryan Reich | timeline score: 7 | |
| Dec 1, 2015 at 19:53 | history | tweeted | twitter.com/StackProgrammer/status/671779149007163392 | ||
| Dec 1, 2015 at 18:52 | vote | accept | Michael | ||
| Dec 1, 2015 at 18:31 | comment | added | amon |
By the way, repeat could be defined in an imperative language as def repeat(x) = { let xs = new LinkedListNode(x); xs.next = xs; xs }, which models the recursion in the data rather than the control flow. Where does that linked list end? Nowhere, never, there is no end node.
|
|
| Dec 1, 2015 at 18:15 | answer | added | Giorgio | timeline score: 21 | |
| Dec 1, 2015 at 18:07 | answer | added | 9000 | timeline score: 2 | |
| Dec 1, 2015 at 18:00 | history | asked | Michael | CC BY-SA 3.0 |