Saturday 30 April 2016

Haskell: replicate: Replicate elements


replicate takes a number n, and an element (It can be a number, string, list etc.,) return a list that contains n copies of the element.

Syntax
replicate n element

Prelude> replicate 5 100
[100,100,100,100,100]
Prelude> 
Prelude> replicate 5 "Hello"
["Hello","Hello","Hello","Hello","Hello"]
Prelude> 
Prelude> replicate 5 [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