[Solved] Haskell: generate and fill list of lists


You can use nested replicate :: Int -> a -> [a]:

makeBoard :: Num a => Int -> Int -> [[a]]
makeBoard h w = replicate h $ replicate w 1

replicate takes thus an Int and an element a and generates a list [a] that contains n times that element. So the second replicate will return a list of ones, and the first replicate will replicate that list h times.

Note that replicate n x is actually equivalent to:

-- equivalent
replicate n x = take n $ repeat x

or shorter:

replicate n = take n . repeat

solved Haskell: generate and fill list of lists