Skip to main content
11 events
when toggle format what by license comment
Aug 26, 2014 at 0:17 vote accept Carcigenicate
Aug 26, 2014 at 0:17
Aug 26, 2014 at 0:17 vote accept Carcigenicate
Aug 26, 2014 at 0:17
Aug 26, 2014 at 0:16 vote accept Carcigenicate
Aug 26, 2014 at 0:17
Aug 26, 2014 at 0:16 vote accept Carcigenicate
Aug 26, 2014 at 0:16
Aug 26, 2014 at 0:16 vote accept Carcigenicate
Aug 26, 2014 at 0:16
Aug 25, 2014 at 23:23 vote accept Carcigenicate
Aug 26, 2014 at 0:16
Aug 25, 2014 at 22:38 history edited user50399 CC BY-SA 3.0
Present code and simplified answer
Aug 25, 2014 at 21:45 history edited user50399 CC BY-SA 3.0
added 15 characters in body
Aug 25, 2014 at 21:42 comment added Carcigenicate the wrapping is only required if the given element is the last on the list. It's wasteful, but otherwise I would have to check if e == last xs. I remember thinking that there was something wrong with that method, but I could have just underthought it.
Aug 25, 2014 at 21:36 comment added Carcigenicate I think you're confused on a couple points. The function returns the next element of a list, following e. The first where binding is a function that splits the list, and puts the given element at the start, and wraps the rest to the end. I wouldn't say that it's circular, as it's only ever called once; the list it produces is still linear. The (x:[]) = Nothing line ensures that the list is at least 2 elements long via pattern matching. The result of nextElem 1 [5,3,9,1,6,8] would be Just 6. It works exactly as intended, it's just long, and as you pointed out,
Aug 25, 2014 at 21:03 history answered user50399 CC BY-SA 3.0