Haskell recursive recursive function

I am trying to make a function that prints char*m ntimes, since the expected result will be ["ccc","ccc"]for input 2 3 c. Here is what I still have:

rectangle :: Int -> Int -> Char -> [string]
rectangle n m c 
    | m > 0 = [concat ([[c]] ++ (rectangle n (m-1) c))] 
    | otherwise = []

I can execute the first part char*m, so it returns ["ccc"]. The fact is, I would also like to repeat my line nonce.

I tried to use replication, but it does not work, but it works if you do it in the console replicate 2 (rectangle 2 3 c).

+3
source share
2 answers

Refactor, , . , . , , . , .

, . . hoogle, hackage, . :

replicate               :: Int -> a -> [a]
replicate n x           =  take n (repeat x)

, . , :

myReplicate                 :: Int -> a -> [a]
myReplicate n x | n <= 0    = []
                | otherwise = x : replicate (n-1) x

---------- ----------------

, , . , . , . , , , n. , map, filter, foldr .., , , .

, - , - , . , - - , . , , - .

, , Learn You a Haskell Real World Haskell, .

+1

:

replicate :: Int -> a -> [a]

rectangle n m c = replicate n (replicate m c)

, , .

+7

All Articles