I am new in Haskell programming.
While practicing I was asked to make a recursive function that looks like this:
repeat1 5 [1,2,3] = [[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
which is
repeat1 :: Int -> a -> [a]
repeat1 0 x = []
repeat1 num x = x : repeat1 (num-1) x
I want to convert it into a foldr function but I can’t 🙁
I have read about the lambda functions and the folding(foldr and foldl) functions from http://en.wikibooks.org/wiki/Haskell/List_processing
Can anybody help please?
Thanks in advance
foldris for functions that consume lists. For producing lists,unfoldris a more natural choice:That said, I think writing it as a plain recursion is more clear in this case.