2011-03-06 87 views

回答

0

刚刚发生了什么问题:

repli Char -> Integer -> String 
repli _ 0 = "" 
repli c i = c : repli c (i-1) 

此功能是令行禁止的形式,但如果你想避免uncurry只是把它写在其uncurried形式:

repli (Char, Integer) -> String 
repli t = if (snd t) = 0 then "" else ((fst t) : (repli ((fst t) (snd t)-1)))) 
0

列表中哈斯克尔是“型均质”:他们只能有一种类型。所以你永远不会有像[['a',9]这样的列表。

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

参见:http://en.wikibooks.org/wiki/Haskell/Lists_and_tuples

但是,什么是你不使用普通的老replicate功能动机是什么?

ghci> replicate 9 'a' 
"aaaaaaaaa"