Conceptually, you can think like this:<div>* Recursion is the only way to loop in functional programming.</div><div>* Things like map, filter, the sexy list comprehension etc. are just nice helpers to help you loop without having to write the recursion yourself.</div><div>* When you can't see a straight forward way to use the helpers, you can always fall back to write the recursion yourself.</div><div><br></div><div>It's a good exercise to spend about an hour to try to implement the map, filter etc. yourself, using recursion, to see what their implementations look like.</div><div><br><br>On Tuesday, March 24, 2015, Mike Houghton <<a href="mailto:mike_k_houghton@yahoo.co.uk">mike_k_houghton@yahoo.co.uk</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks guys - I think the light has just gone on!<br>
;)<br>
<br>
> On 23 Mar 2015, at 22:57, Ngoc Dao <<a href="javascript:;" onclick="_e(event, 'cvml', 'ngocdaothanh@gmail.com')">ngocdaothanh@gmail.com</a>> wrote:<br>
><br>
> Mike,<br>
><br>
> You may have noticed Frerich was saying about recursion.<br>
> I will provide you some more topics/keywords so that you can<br>
> investigate further:<br>
><br>
> You should practise writing the recursion in 2 ways:<br>
> normal recursion and tail recursion (to avoid stackoverflow when the<br>
> recursion depth is large)<br>
><br>
> For the tail recursion, you use the accumulator pattern, which is very<br>
> common in functional programming.<br>
><br>
> On Tue, Mar 24, 2015 at 7:46 AM, Frerich Raabe <<a href="javascript:;" onclick="_e(event, 'cvml', 'raabe@froglogic.com')">raabe@froglogic.com</a>> wrote:<br>
>> Hi Mike,<br>
>><br>
>> On 2015-03-23 23:06, Mike Houghton wrote:<br>
>>><br>
>>> I’m working through <a href="http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf" target="_blank">http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf</a> [1]<br>
>>> - the homework for the CIS 194 Haskell course.<br>
>>> I ‘stuck’ on question 6!<br>
>>> If anyone has done this I’d really appreciate a pointer to solving it.<br>
>><br>
>><br>
>> Just thinking out loud:<br>
>><br>
>> Consider that to get all lists of length 2, you could add (e.g. prepend)<br>
>> each of the six colors to each of the lists of length 1. And to get each of<br>
>> the lists of length 1 you prepend each of the six colors to each of the<br>
>> lists of length 0.<br>
>><br>
>> Does that help? :-)<br>
>><br>
>> --<br>
>> Frerich Raabe - <a href="javascript:;" onclick="_e(event, 'cvml', 'raabe@froglogic.com')">raabe@froglogic.com</a><br>
>> <a href="http://www.froglogic.com" target="_blank">www.froglogic.com</a> - Multi-Platform GUI Testing<br>
>> _______________________________________________<br>
>> Beginners mailing list<br>
>> <a href="javascript:;" onclick="_e(event, 'cvml', 'Beginners@haskell.org')">Beginners@haskell.org</a><br>
>> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
> _______________________________________________<br>
> Beginners mailing list<br>
> <a href="javascript:;" onclick="_e(event, 'cvml', 'Beginners@haskell.org')">Beginners@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'Beginners@haskell.org')">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>