-4

我正在尝试 l = ["","a","aa","aaa",...]在 haskell 中创建此流。

有人能帮我吗?

4

4 回答 4

7

将 inits 与 repeat 结合起来:

λ: let l = inits $ repeat 'a'
λ: take 10 l
["","a","aa","aaa","aaaa","aaaaa","aaaaaa","aaaaaaa","aaaaaaaa","aaaaaaaaa"]
于 2013-05-27T14:00:00.613 回答
6

我们可以通过迭代地将元素consing到空列表中来到达那里

iterate :: (a -> a) -> a -> [a]

只是做

iterate ('a':) ""
于 2013-05-27T17:32:40.947 回答
2

不使用预定义函数:

l = l' ""
    where l' s = s : l' ('a':s)
于 2013-05-27T20:02:35.807 回答
1
[replicate i 'a' | i <- [0..]]

这不是完全先进的东西。

于 2013-05-27T13:55:43.520 回答