How to convert a list of (Char,Int) to a string with the given number of repeated chars?

前端 未结 4 1673
予麋鹿
予麋鹿 2020-12-22 05:23

How can I convert [(char,Int)] to a String of the Int in the second component gives the number of repetitions of the character in the first component? For examp

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-22 06:10

    The facetious and horrible answer:

    Prelude> let replignore ((_,x):[]) = [replicate x 'b']; replignore ((_,x):xs) = replicate x 'a' : replignore xs
    Prelude> replignore [(a,9),(b,10)]
    :1:13: Not in scope: `a'
    :1:19: Not in scope: `b'
    Prelude> let a = undefined
    Prelude> let b = undefined
    Prelude> replignore [(a,9),(b,10)]
    ["aaaaaaaaa","bbbbbbbbbb"]
    

    But it didn't quite fit the specs since it includes the quotation marks in the answer. ;)

    My point is, you need quotes around your Char and String literals.

提交回复
热议问题