How do you solve this Haskell problem?

Posted by Linda Cohen on Stack Overflow See other posts from Stack Overflow or by Linda Cohen
Published on 2010-05-05T22:37:39Z Indexed on 2010/05/05 22:58 UTC
Read the original article Hit count: 128

Filed under:
|
|

I want to define a function replicate to replicate a list of numbers by its value using only list comprehension, for example:

replicate [5,1,3,2,8,1,2] output: [5,5,5,5,5,1,3,3,3,2,2,8,8,8,8,8,8,8,8,1,2,2]

I know this would be easy to use the 'replicate' built in function but only list comprehension is allow, how can I do this?

THANKS!

© Stack Overflow or respective owner

Related posts about haskell

Related posts about list