I want to write a Haskell program that replicates the elements of a list a given number of times. Here's my code:
repli :: [a] -> a -> [a]
repli xs n = foldl1 (\x -> take n (repeat x)) xs
My problem is I get the following errors when compiling:
'take' is applied to too many arguments
couldn't match expected type '[a]->[a]' with actual type '[[a]]'
repli [1,2] 2
to generate[1,1,2,2]
, and not[1,2,1,2]
. Is that right? Please clarify this in your question, since answers below sometimes chose the second interpretation. – chi