-- generates names in the following order
-- a, b, c ... z, aa, ba, ca, ... za, ab, bb, cb ...
nextName :: String -> String
nextName [] = "a"
nextName (x:xs) = if x == 'z' then 'a' : nextName xs else succ x : xs
-- verify if the number of names generated is as expected.
countNames :: String -> String -> Int
countNames start end = loop 1 start
where
loop acc next =
if next == end then
acc
else
loop (acc + 1) (nextName next)
运行countNames "a" "zzzzzz"
在ghci中简单字符串生成中的空间泄漏。为什么?
在我的COM运行它占据了整个内存和需要大量的时间来完成的地狱。
如果有人指出发生空间泄漏的位置和原因,请注意它吗?
制作'loop'严格其参数。 – Satvik
你是如何编译的? – jberryman