Hi all,<div><br></div><div>I high school programmer and just started learning Haskell. Haskell so far seems to be an awesome language. I began reading &quot;Learn you Haskell for a Great Good!&quot; I am confused with list comprehension, as I am coming from an imperative programming language (Java). From my understanding, list comprehension is synonymous to Java&#39;s for-loop and what not. </div>
<div><br></div><div>For example: </div><div><br></div><div><font face="&#39;courier new&#39;, monospace">let xs = [1,2,3,4,5]</font></div><div><font face="&#39;courier new&#39;, monospace">[x | x &lt;- xs]</font></div><div>
<br></div><div>I believe it is saying that &quot;bound x to xs, and do (print) x.&quot; </div><div><br></div><div>Another example:</div><div><br></div><div><div><font face="&#39;courier new&#39;, monospace">let rightTriangles&#39; = [ (a,b,c) | c &lt;- [1..10] , b &lt;- [1.. c], a &lt;- </font><span style="font-family:&#39;courier new&#39;,monospace">[1.. b], a^2 + b^2 == c^2, a+b+c == 24]</span></div>
<div><font face="&#39;courier new&#39;, monospace">ghci &gt; rightTriangles&#39;</font></div><div><font face="&#39;courier new&#39;, monospace">[(6 ,8 ,10)]</font></div><div><br></div><div>I believe it is saying &quot;store c with the numbers 1-10, b is length of c, and a is the length of b. Print the answer (a,b,c) which satisfies a^2 + b^2 == c^2, a+b+c == 24.</div>
<div>It may seem that I am answering my own question, but when it becomes more complicated or I am ask to do specific tasks that involves list comprehensions, I do not know how to read or compose one. </div></div><div><br>
</div><div>Second, can someone do a line by line breakdown of this code? The book does a sub-par job explaining it.</div><div><font face="&#39;courier new&#39;, monospace">-- Creating our own sum function</font></div><div>
<div><font face="&#39;courier new&#39;, monospace">sum &#39; :: (Num a) =&gt; [a] -&gt; a</font></div><div><font face="&#39;courier new&#39;, monospace">sum &#39; [] = 0</font></div><div><font face="&#39;courier new&#39;, monospace">sum &#39; (x:xs) = x + sum &#39; xs</font></div>
</div><div><br></div><div>Summed up: How did you learn Haskell and how long did it take before you became competent? This is my second day and I am already running into problems. I have to re-read things where as Java it came easy to me. Any book or tutorials? Can someone explain list comprehension and my recursion code?</div>
<div><br></div><div>Thanks,</div><div>- Cody</div><div><br></div><div>p.s The questions so far have been over my head (is this a &quot; true beginner&#39;s email list&quot;?), I&#39;ll try to answer what I can.</div><div>
<br></div>