Re: [Haskell] Function to replace given element in list

2016-07-19 Thread David Feuer
A zipper is a good way to separate the search from the replacement. But the problem at hand does not require such a separation! If you don't need that, a zipper seems like overkill. On Jul 19, 2016 7:39 PM, "Carl Folke Henschen Edman" wrote: On Tue, Jul 19, 2016 at 6:13 PM, David Feuer wrote:

Re: [Haskell] Function to replace given element in list

2016-07-19 Thread Carl Folke Henschen Edman
On Tue, Jul 19, 2016 at 6:13 PM, David Feuer wrote: > Using a zipper will not get you very far here. The best way would > likely be to replace the list with a balanced search tree. > That depends on the pattern of access and usage. For some a zippered list will outperform a self-balancing tree

Re: [Haskell] Function to replace given element in list

2016-07-19 Thread David Feuer
Using a zipper will not get you very far here. The best way would likely be to replace the list with a balanced search tree. Sticking with the list for now, your choice to replace the entire list with [5] if the sought element is not found seems a bit peculiar, and also leads to an inherent efficie

Re: [Haskell] Function to replace given element in list

2016-07-19 Thread Carl Folke Henschen Edman
On Tue, Jul 19, 2016 at 4:08 PM, Niely Boyken wrote: > let i = elemIndex toReplace lst in > > case i of > Just i -> > let z = splitAt i lst > x = fst z > y = (snd z) > in >

Re: [Haskell] Function to replace given element in list

2016-07-19 Thread Richard Fung
Hi Niely, everything after the "in" in your "let in" is one expression. In other words all of this: init x x ++ newNmr x ++ y is being read as one line.. so init x x ++ newNmr x ++ y which is why the compiler is complaining