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:
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
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
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
>
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