How to print the same char n times in Haskell

后端 未结 3 429
无人共我
无人共我 2021-01-21 00:01

I would like to print a char underlining a String n times, with n the length of the String in Haskell.

How should I do this?

My String is: \"Available Chars (x)\

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-21 00:48

    A possibility is to (re)implement replicate, for instance as follows,

    replicate' :: Int -> a -> [a]                
    replicate' n x = if (n <= 0) then [] else (x : replicate (n-1) x) 
    

提交回复
热议问题