<div dir="ltr"><div><div><div><div><div><div>Hi<br><br></div>I'm trying to make a custom function to replace a given element in a list.<br><br></div>Code:<br>    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><br></div>Error:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">1)<br> * Couldn't match expected type `[a] -> [a]' with actual type `[a]'<br>    * The function `init' is applied to two arguments,<br>      but its type `[a] -> [a]' has only one<br>      In the first argument of `(++)', namely `init x x'<br>      In the expression: init x x ++ newNmr x ++ y<br>    * Relevant bindings include<br>        y :: [a] (bound at C:\users\niel\desktop\test2.hs:41:21)<br>        x :: [a] (bound at C:\users\niel\desktop\test2.hs:40:21)<br>        z :: ([a], [a]) (bound at C:\users\niel\desktop\test2.hs:39:21)<br>        newNmr :: [a] (bound at C:\users\niel\desktop\test2.hs:34:30)<br>        lst :: [a] (bound at C:\users\niel\desktop\test2.hs:34:26)<br>        toReplace :: a (bound at C:\users\niel\desktop\test2.hs:34:16)<br>        (Some bindings suppressed; use -fmax-relevant-binds=N or -fno-max-relevant-binds)<br>2)<br> * Couldn't match expected type `[a] -> [a]' with actual type `[a]'<br>    * The function `newNmr' is applied to one argument,<br>      but its type `[a]' has none<br>      In the first argument of `(++)', namely `newNmr x'<br>      In the second argument of `(++)', namely `newNmr x ++ y'<br>    * Relevant bindings include<br>        y :: [a] (bound at C:\users\niel\desktop\test2.hs:41:21)<br>        x :: [a] (bound at C:\users\niel\desktop\test2.hs:40:21)<br>        z :: ([a], [a]) (bound at C:\users\niel\desktop\test2.hs:39:21)<br>        newNmr :: [a] (bound at C:\users\niel\desktop\test2.hs:34:30)<br>        lst :: [a] (bound at C:\users\niel\desktop\test2.hs:34:26)<br>        toReplace :: a (bound at C:\users\niel\desktop\test2.hs:34:16)<br>        (Some bindings suppressed; use -fmax-relevant-binds=N or -fno-max-relevant-binds)<br></blockquote><br></div>I've tried a lot, but I always got an error.<br></div>What am I doing wrong?<br><br></div>Thanks!<br></div>