[Haskell-beginners] howto reason infinite lists
prad
prad at towardsfreedom.com
Mon Jun 21 14:58:11 EDT 2010
i'm trying to figure out how to think out the circular definition for
an infinite list and would appreciate suggestions.
consider
ones = 1 : ones
this essentially says 1 : (1 : (1 : (1 : ones))) with ones being given
by the original def.
however, i had trouble with this one
fib = 1 : 1 : [ a+b | (a,b) <- zip fib (tail fib) ]
initially, i tried building it element by element and got stuck when i
thought of what was
fib
tail fib
and what was being zipped
so i thought it out differently by assuming the infinite list was
already created in the following fashion.
fib is [1,1,a,b,c,d,e, ..]
tail fib is [1,a,b,c,d,e,f, ..]
to find a, we zip fib and tail fib getting (1,1) and add getting 2:
fib is [1,1,2,b,c,d,e, ..]
tail fib is [1,2,b,c,d,e,f, ..]
get b from the next zip (1,2) and add giving 3:
fib is [1,1,2,3,c,d,e, ..]
tail fib is [1,2,3,c,d,e,f, ..]
c comes from (2,3) which adds to 5:
fib is [1,1,2,3,5,d,e, ..]
tail fib is [1,2,3,5,d,e,f, ..]
this way of thinking about it makes sense to me, but i'd be curious to
know if it is proper thinking.
it seems to me that if we consider the list to be already built, we can
apply zip successively to get the next part of it, but if we think
recursively we start at the beginning at each recursive level and go
nowhere.
--
In friendship,
prad
... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's
More information about the Beginners
mailing list