我正在尝试 l = ["","a","aa","aaa",...]
在 haskell 中创建此流。
有人能帮我吗?
将 inits 与 repeat 结合起来:
λ: let l = inits $ repeat 'a'
λ: take 10 l
["","a","aa","aaa","aaaa","aaaaa","aaaaaa","aaaaaaa","aaaaaaaa","aaaaaaaaa"]
我们可以通过迭代地将元素consing到空列表中来到达那里
iterate :: (a -> a) -> a -> [a]
只是做
iterate ('a':) ""
不使用预定义函数:
l = l' ""
where l' s = s : l' ('a':s)
[replicate i 'a' | i <- [0..]]
这不是完全先进的东西。