剛開始學習Haskell。在Haskell中調用函數 - 初學者問題
我有這裏面空的源文件:
pe :: (Integral a) => a -> a
pe y = sum [x | x <- [1..y-1], x `mod` 3 == 0 || x `mod` 5 == 0]
現在,如果我GHCI這一點,我可以叫PE,像這樣:
*Main> pe 1000
233168
我如何把它從我的源代碼中文件?如果我有
pe 1000
它返回一個神祕的錯誤:
GHC stage restriction: `pe'
is used in a top-level splice or annotation,
and must be imported, not defined locally
In the expression: pe 1000
我需要聲明它主要還是什麼?
或'main = mapM_(print.pe)[1..1000]'如果您需要爲大量的值進行操作。 – alternative 2011-05-28 00:20:18