<div dir="ltr">Hi Niely,<div><br></div><div>everything after the "in" in your "let in" is one expression. In other words all of this:</div><div><span style="font-size:12.8px"> init x</span><br style="font-size:12.8px"><span style="font-size:12.8px"> x ++ newNmr</span><br style="font-size:12.8px"><span style="font-size:12.8px"> x ++ y</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">is being read as one line.. so</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">init x x ++ newNmr x ++ y</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">which is why the compiler is complaining that you are applying init to two values (init x x).</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">I think what you want is actually something more like </span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">(init x) ++ [newNmr] ++ y</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">assuming newNmr is a number and not already a list.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">I'm not entirely sure what you were trying to do there but you seem a bit confused.. "init x" on its own doesn't actually do anything; it computes a value but you aren't assigning it to anything here.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">If you wanted to keep those exact expressions you could instead do</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">let x0 = init x</span></div><div><span style="font-size:12.8px"> x1 = x0 ++ newNmr</span></div><div><span style="font-size:12.8px">in x1 ++ y</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">and x1 ++ y would be the thing that actually gets return.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">In any case I am certainly no expert so hopefully someone else can explain this better than I can.</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 19, 2016 at 1: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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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>
<br>_______________________________________________<br>
Haskell mailing list<br>
<a href="mailto:Haskell@haskell.org">Haskell@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell</a><br>
<br></blockquote></div><br></div>