Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Repeat' in Haskell?

Tags:

list

haskell

I'm very new to Haskell, and I have a simple question.

What function can I use with a and b that will result in a, b times.

Example:
a = 4 | b = 3
Would return:
[4, 4, 4]

Thanks!

like image 761
Peter Avatar asked Apr 08 '11 08:04

Peter


1 Answers

replicate:

replicate 3 4

will be:

[4,4,4]

When you know what's the type of the function you need (in this case it was quite obvious that the function you needed had a type similar to Int -> a -> [a]) you can use Hoogle in order to find it.

like image 177
peoro Avatar answered Oct 18 '22 10:10

peoro