Repeat a string: Difference between revisions

→‎{{header|Haskell}}: Or unpacking the mechanism of '''replicate''' a little, and using a monoid operation
No edit summary
(→‎{{header|Haskell}}: Or unpacking the mechanism of '''replicate''' a little, and using a monoid operation)
Line 798:
To repeat a single character:
<lang haskell>replicate 5 '*'</lang>
 
Or, unpacking the mechanism of '''replicate''' a little, and using a monoid operation:
<lang haskell>repString :: String -> Int -> String
repString s n =
let rep x = xs
where
xs = mappend x xs
in take (n * length s) $ rep s
 
main :: IO ()
main = print $ repString "ha" 5</lang>
{{Out}}
<pre>"hahahahaha"</pre>
 
=={{header|HicEst}}==
9,655

edits