我正在尝试通过编写简单的文件复制工具来学习Haskell:
main = do
putStr "Source: "
srcPath <- getLine
putStr "Destination: "
destPath <- getLine
putStrLn ("Copying from " ++ srcPath ++ " to " ++ destPath ++ "...")
contents <- readFile srcPath
writeFile destPath contents
putStrLn "Finished"
这让我感到
GHCi, version 6.10.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( D:\Test.hs, interpreted )
D:\Test.hs:8:22: Not in scope: `contents'
Failed, modules loaded: none.
Prelude>
我不理解编译器错误,因为变量看起来没问题。错在哪里?
这是一个复现文件:在rapidshare上。