Saturday 30 April 2016

Haskell: repeat: Produce infinite list


repeat takes an element and produces an infinite list of just that element.
Prelude> take 10 (repeat 10)
[10,10,10,10,10,10,10,10,10,10]
Prelude> 
Prelude> take 10 (repeat "Hello")
["Hello","Hello","Hello","Hello","Hello","Hello","Hello","Hello","Hello","Hello"]
Prelude> 
Prelude> take 10 (repeat [2, 3, 5, 7, 11])
[[2,3,5,7,11],[2,3,5,7,11],[2,3,5,7,11],[2,3,5,7,11],[2,3,5,7,11],[2,3,5,7,11],[2,3,5,7,11],[2,3,5,7,11],[2,3,5,7,11],[2,3,5,7,11]]


Previous                                                 Next                                                 Home

No comments:

Post a Comment