Conceptually, you can think like this:
* Recursion is the only way to loop in functional programming.
* Things like map, filter, the sexy list comprehension etc. are just nice helpers to help you loop without having to write the recursion yourself.
* When you can't see a straight forward way to use the helpers, you can always fall back to write the recursion yourself.

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.


On Tuesday, March 24, 2015, Mike Houghton <mike_k_houghton@yahoo.co.uk> wrote:
Thanks guys - I think the light has just gone on!
;)

> On 23 Mar 2015, at 22:57, Ngoc Dao <ngocdaothanh@gmail.com> wrote:
>
> Mike,
>
> You may have noticed Frerich was saying about recursion.
> I will provide you some more topics/keywords so that you can
> investigate further:
>
> You should practise writing the recursion in 2 ways:
> normal recursion and tail recursion (to avoid stackoverflow when the
> recursion depth is large)
>
> For the tail recursion, you use the accumulator pattern, which is very
> common in functional programming.
>
> On Tue, Mar 24, 2015 at 7:46 AM, Frerich Raabe <raabe@froglogic.com> wrote:
>> Hi Mike,
>>
>> On 2015-03-23 23:06, Mike Houghton wrote:
>>>
>>> I’m working through http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf [1]
>>> - the homework for the CIS 194 Haskell course.
>>> I ‘stuck’ on question 6!
>>> If anyone has done this I’d really appreciate a pointer to solving it.
>>
>>
>> Just thinking out loud:
>>
>> Consider that to get all lists of length 2, you could add (e.g. prepend)
>> each of the six colors to each of the lists of length 1. And to get each of
>> the lists of length 1 you prepend each of the six colors to each of the
>> lists of length 0.
>>
>> Does that help? :-)
>>
>> --
>> Frerich Raabe - raabe@froglogic.com
>> www.froglogic.com - Multi-Platform GUI Testing
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners