Haskell, list of natural number
Posted
by Hellnar
on Stack Overflow
See other posts from Stack Overflow
or by Hellnar
Published on 2010-03-21T13:03:57Z
Indexed on
2010/03/21
13:11 UTC
Read the original article
Hit count: 186
Hello, I am an absolute newbie in Haskell yet trying to understand how it works.
I want to write my own lazy list of integers such as [1,2,3,4,5...].
For list of ones I have written
ones = 1 : ones
and when tried, works fine:
*Main> take 10 ones
[1,1,1,1,1,1,1,1,1,1]
How can I do the same for increasing integers ?
I have tried this but it indeed fails:
int = 1 : head[ int + 1]
And after that how can I make a method that multiplies two streams? such as:
mulstream s1 s2 = head[s1] * head[s2] : mulstream [tail s1] [tail s2]
© Stack Overflow or respective owner