FWIW here is another solution, using only lists. (Whereas I agree with others who suggested using <i>proper</i> data structures rather than &#39;lists for everything&#39;)<br><br><div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">-- walks over both lists, always consumes an element from </span></div>
<div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">-- the first list, </span><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">consumes an element from the second list</span></div>
<div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">-- only if values are equal.</span></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">ix :: Ord a =&gt; [a] -&gt; [a] -&gt; [b -&gt; Maybe b]</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">ix (a:as) (b:bs) | a == b = Just : ix as bs</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">ix (a:as) (b:bs) | a &lt; b  = const Nothing : ix as (b:bs)</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">ix _ _ = []</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">-- consume a value from the second list, only if the current</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">-- function coming from the </font><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">first list evaluates to a Just</span></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">proj :: [a -&gt; Maybe b] -&gt; [a] -&gt; [Maybe b]</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">proj [] _ = []</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">proj (f:fs) (x:xs) =</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">    let fx  = f x</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">        nextxs Nothing = x : xs</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">        nextxs _       = xs</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">    in  fx : proj fs (nextxs fx)</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">*Main&gt; proj (ix inp_a inp_b) inp_c</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">[Just 2,Just 1,Nothing,Nothing,Nothing,Just (-5)]</font></div></div><div><br></div><div>And of course, if you really want to substitute 0&#39;s for Nothings, you can do it using something like:</div>
<div><br></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">to0s :: Num a =&gt; [Maybe a] -&gt; [a]</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">to0s = map (fromMaybe 0)</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">*Main&gt; to0s $ proj (ix inp_a inp_b) inp_c</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">[2,1,0,0,0,-5]</font></div></div><div><br></div><div>Hope this helps,</div><div>Ozgur</div><div><br><div class="gmail_quote">On 15 September 2010 00:35, Lorenzo Isella <span dir="ltr">&lt;<a href="mailto:lorenzo.isella@gmail.com">lorenzo.isella@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Dear All,<br>
I still have to find my way with immutable lists and list comprehension.<br>
Consider the following lists<br>
<br>
A=[0,10,20,30,40,50]<br>
B=[0,10,50] (i.e. B is a subset of list A; list A is already ordered in increasing order and so is B).<br>
C=[2,1,-5] i.e. there is a corresponding element in C for every element in B.<br>
<br>
Now, I would like to define a new list D having length equal to the length of A. The elements of D in the position of the elements of A in common with B are equal to the corresponding entries in C, whereas the other ones are zero i.e.<br>

D=[2,1,0,0,0,-5]. How can I achieve that? The first thought that comes to my mind is to define a list of zeros which I would modify according to my needs, but that is not allowed...<br>
Many thanks<br>
<br>
Lorenzo<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br><br>
</div></div></div>