复制功能帮助 [英] replicate function help

查看:90
本文介绍了复制功能帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

如何将(Char,Int)列表转换为具有给定重复字符数的字符串?


我怎么做[(char,int)] - >字符串复制不使用uncurry



例如在['a',9]中输入并且输出aaaaaaaaa

解决方案

Haskell中的列表是类型齐次的:它们只能有一种类型。所以你永远不会有像`['a',9]这样的列表。

You can 有一个元组( '一个',9)。你也可以有一个元组列表,例如 [('a',9)] 。但是,那么这个列表中的所有元组必须是(Char,Integer)



另请参阅: http://en.wikibooks.org/wiki/Haskell/Lists_and_tuples



但是,如果你不使用普通的旧的 replicate 功能?

  ghci的>复制9'a'
aaaaaaaaa


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

how can i do a [(char,int)] -> String with replicate not using uncurry

for example type in ['a',9] and it out puts "aaaaaaaaa"

解决方案

Lists in Haskell are "type-homogeneous": they can only have one type in them. So you can't ever have a list like `['a',9].

You can have a tuple ('a',9). You can also have a list of tuples, such as [('a',9)]. But then all tuples in that list must be of type (Char, Integer).

See also: http://en.wikibooks.org/wiki/Haskell/Lists_and_tuples

But what is your motivation for not using the plain old replicate function?

ghci> replicate 9 'a'
"aaaaaaaaa"

这篇关于复制功能帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆