<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px"><div id="yui_3_16_0_ym19_1_1467169159488_5092"><br></div><div id="yui_3_16_0_ym19_1_1467169159488_5092">Hi,</div><div id="yui_3_16_0_ym19_1_1467169159488_5092"><br></div><div id="yui_3_16_0_ym19_1_1467169159488_5092"><br></div><div id="yui_3_16_0_ym19_1_1467169159488_5092">Problem: I would like to generate an infinite list of Fibonacci numbers. Although the below code does not work.</div><div id="yui_3_16_0_ym19_1_1467169159488_5092"><br></div><div id="yui_3_16_0_ym19_1_1467169159488_5092"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5129">fibs :: [Integer]</div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5130">fibs = 0 : 1 : [ n | x <-[2..], let n = ((fibs !! x-1) + (fibs !! x-2))]</div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5130"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5130"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5130">Thought: I'm assuming that I'm ignorant on how ranges/generators work with a list comprehension, which is why this code is not working.<br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5130"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5130">ghci output:</div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5130"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5427">*Main> fibs !! 0</div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5428">1</div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5429">*Main> fibs !! 1</div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5430">2</div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5431">*Main> fibs !! 2</div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5431"> <br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5431">When I try and access the third element in the list ghci simply stalls.</div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5431"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5431">Can someone please give me a little more insight on why my code is not working.</div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5431"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5431">Thanks in advance.</div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5431"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5431">drjoliv</div><div dir="ltr" id="yui_3_16_0_ym19_1_1467169159488_5431"><br></div></div></body></html>