我试图通过编写一个简单的文件副本util来学习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"
Run Code Online (Sandbox Code Playgroud)
这让我感到高兴
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 …Run Code Online (Sandbox Code Playgroud) 我遇到了棘手的缩进造成的问题,这里的代码看起来 是VI:
1 import Data.List
2 myQuickSort [] = []
3 myQuickSort (x:xs) = myQuickSort smaller ++ [x] ++ myQuickSort bigger
4 where smaller = filter ( < x ) xs
5 bigger = filter ( >=x ) xs
Run Code Online (Sandbox Code Playgroud)
但是在./cat 3.hs之后,看起来,
root@pierr-desktop:/opt/playGround/haskell# cat 3.hs
import Data.List
myQuickSort [] = []
myQuickSort (x:xs) = myQuickSort smaller ++ [x] ++ myQuickSort bigger
where smaller = filter ( < x ) xs
bigger = filter ( >=x ) xs
Run Code Online (Sandbox Code Playgroud)
然后将其加载到ghci中
GHCi, version …Run Code Online (Sandbox Code Playgroud)