
I am a haskell beginner and wondering how the following function works (in procedure) : oddsFrom3 :: [Integer] oddsFrom3 = 3 : map (+2) oddsFrom3 Thanks for your help. -- A GNU [1] LINUX [2] Patron Links: ------ [1] http://gnu.org [2] http://www.linuxfoundation.org/

Hi Debdut, On Mon, Aug 17, 2015 at 04:44:55AM -0400, Debdut Karmakar wrote:
I am a haskell beginner and wondering how the following function works (in procedure) :
oddsFrom3 :: [Integer] oddsFrom3 = 3 : map (+2) oddsFrom3
Thanks for your help.
Try to expand a few steps of the recursion by hand e.g.: 3 : (map (+2) (3 : map (+2) (3 : map (+2) ...))) As you can see, the deeper you go more 'map (+2)' are applied to '3'. Greetings, Daniel

This is a classical example that combines lazy (actually the real name is non-strict) lists and recursion. You can find an explanation of such a combination here http://stackoverflow.com/questions/6273621/understanding-a-recursively-defin... Silvio
participants (3)
-
Daniel Trstenjak
-
Debdut Karmakar
-
Silvio Frischknecht