好了,從my previous question我已經結束了與下面的代碼下面就:運行一個編譯好的Haskell程序;得到錯誤
module Main where
import Data.List
chain n | n == 0 = error "What are you on about?"
| n == 1 = [1]
| rem n 2 == 0 = n : chain (n `div` 2)
| otherwise = n : chain (3 * n + 1)
chainLength n = (n,length (chain n))
array = map chainLength [1..999]
lengths = map chainLength [1..1000000]
compareSnd (_, y1) (_, y2) = compare y1 y2
longestChain = maximumBy compareSnd lengths
從GHCI這個加載罰款作爲一個模塊,但運行longestChain與堆棧溢出結束。此問題的解決方案不是完全重寫,而是增加堆棧大小。 GHC --make chain.hs
我得到一個錯誤: 所以我編譯
chain.hs:1:0: The function 'main' is not defined in the module 'main'
在哪裏,我需要在把主要的功能,使其正常編譯。
然後一旦編譯完成,我該如何讓它運行輸出或使用命令? 我假設有:
ghc chain.o +RTS -K128M
編譯後,我只需要它具有大堆棧大小運行longestChain。
謝謝,你是救命的人。由於你的幫助,我在Haskell的技能已經大大提高。 – 2009-08-06 13:53:46
當你到達「邪惡」monad時打電話給我;-) – 2009-08-06 14:12:21