<div dir="ltr"><div><div><div>Yeah, the question is so open that it's hard to answer. Was thinking recommending to inline the desired list all together, but thought it too impolite :).<br><br></div>But the `concatMap` is the simplest one (to replace all "z"s that is), and if the OP is interested, then for lists >>= is defined as concatMap, so:<br><br>a = ["x", "y", "z"]<div>b = ["f", "g"]</div><div><br></div><div>f :: String -> [String]<br></div><div>f str = case str of</div><div>  "z" -> b</div><div>  _ -> [str]<br></div><br></div>answer = a >>= f<br><br></div>(Didn't run this through the compiler)<br><div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 6, 2017 at 12:20 AM, Richard A. O'Keefe <span dir="ltr"><<a href="mailto:ok@cs.otago.ac.nz" target="_blank">ok@cs.otago.ac.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
<br>
On 4/11/17 11:48 PM, mirone wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello everyone!<br>
If I have a list A : ["x", "y", "z"]<br>
and a list B: ["f", "g"].<br>
Here is my question:<br>
What's the simplest way to replace "z" in the list A by list B, and get<br>
["x", "y", "f", "g"] ?<br>
</blockquote>
<br></div></div>
f _ _ = ["x","y","f","g"]<br>
<br>
That's a joke, but it really isn't clear what the question means.<br>
One possibility is<br>
<br>
f a b = init a ++ b<br>
<br>
f [1,2,3,4,5] [9,8,7] => [1,2,3,4,9,8,7]<br>
<br>
If you mean that you want to replace "z" by ... wherever it occurs,<br>
something like<br>
-- (f needle straws haystack) replaces each occurrence of needle as<br>
-- an element of haystack with the elements of straws.<br>
f :: Eq t => t -> [t] -> ([t] -> [t])<br>
f needle straws =<br>
  concatMap (\straw -> if straw == needle then straws else [straw])<br>
<br>
f "z" ["f","g"] ["x","z","y","z"] => ["x","f","g","y","f","g"]<br>
<br>
Your question admits of too many generalisations for us to be really<br>
helpful.<div class="HOEnZb"><div class="h5"><br>
______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</a><br>
Only members subscribed via the mailman list are allowed to post.</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Markus Läll<br></div>
</div>