Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating an infinite sequence in Haskell

I know that infinite sequences are possible in Haskell - however, I'm not entirely sure how to generate one

Given a method

generate::Integer->Integer

which take an integer and produces the next integer in the sequence, how would I build an infinite sequence out of this?

like image 457
Martin Avatar asked Mar 21 '26 18:03

Martin


1 Answers

If you want your sequence to start from 1 then it is -

iterate generate 1

Please notice that first letter of function is lowercase, not uppercase. Otherwise it would be data type, not function.

//edit: I just realized not just data types start with capital, it could be data constructor or type class as well, but that wasn't the point. :)

like image 129
Martin Jonáš Avatar answered Mar 24 '26 15:03

Martin Jonáš