<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 19, 2016 at 4:08 PM, Niely Boyken <span dir="ltr"><<a href="mailto:niely.b0yk3n@gmail.com" target="_blank">niely.b0yk3n@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div> let i = elemIndex toReplace lst in<br> <br> case i of<br> Just i -><br> let z = splitAt i lst<br> x = fst z<br> y = (snd z)<br> in<br> init x<br> x ++ newNmr<br> x ++ y<br> <br> Nothing -> [5]<br></div></blockquote></div><br>If I understand what you are trying to do correctly, a more idiomatic (and syntactically correct code) would be:</div><div class="gmail_extra"><br></div><div class="gmail_extra"> case elemIndex toReplace lst of</div><div class="gmail_extra"> Just i -> let (xs,_:ys)=splitAt i lst in xs ++ (newNmr:ys)</div><div class="gmail_extra"> _ -> [5]</div><div class="gmail_extra"><br></div><div class="gmail_extra">In more general terms, replacing individual elements in standard lists is a very inefficient operation for large lists. Having you considered using a Zipper List which allows you to efficiently replace elements at a focal point (and also to traverse the list forward and backward efficiently)?</div><div class="gmail_extra"><div><div class="gmail_signature" data-smartmail="gmail_signature"><br></div><div class="gmail_signature" data-smartmail="gmail_signature">An example implementation of a Zipper (just for Lists) is at <a href="https://hackage.haskell.org/package/ListZipper-1.2.0.2/docs/Data-List-Zipper.html">https://hackage.haskell.org/package/ListZipper-1.2.0.2/docs/Data-List-Zipper.html</a>, but implementing your own is an easy and instructive exercise.</div><div class="gmail_signature" data-smartmail="gmail_signature"><br> Carl Edman</div></div>
</div></div>