編輯: 我總共有4個錯誤。解析輸入錯誤`=',沒有indentaion,而不是ghci
在第5行我有「」「,這沒有任何意義。
在第9行中我有「map(asciiRotC)」。這應該是 「地圖(asciiRotC N)」
在管線13我有 「×:XS這應該是 」:「。
在最後一行中我」(X XS)asciiRotWith 0(+ 1) 「這應該是」 ......(+1)0"
這裏是我完整的代碼(文件名爲asciiRot.hs):
import System.Environment
import System.IO
asciiRotC :: Int -> Char -> Char
asciiRotC _ '' = ''
asciiRotC 0 msg = msg
asciiRotC n msg = toEnum (33 + (n + (fromEnum msg) - 33) `mod` 93) :: Char
asciiRot :: Int -> String -> String
asciiRot n msg = map (asciiRotC) msg
asciiRotWith :: (Int->Int) -> Int -> String -> String
asciiRotWith _ _ "" = ""
asciiRotWith f acc x:xs = (asciiRotC acc x) : (asciiRotWith f (f acc) xs)
main = do
args <- getArgs
putStrLn $ asciiRotWith 0 (+1) (head args)
我得到的錯誤是:asciiRot.hs:8:16:輸入解析錯誤'='
我已經搜索了類似的錯誤,發現它們大多與縮進或試圖在ghci中做的事情有關,但事實並非如此,我試圖編譯,並使用空格來縮進。
我試圖在第8行中添加一個額外的空間,以匹配所有的音符,但錯誤不會改變。
我使用的是Debian 7,ghc「The Glorious Glasgow Haskell Compilation System,version 7.4.1」。我在vim寫我的代碼,並用ghc編譯asciiRot.hs
早期版本可以工作。那就是:
asciiRot :: Int -> String -> String
asciiRot _ "" = ""
asciiRot 0 msg = msg
asciiRot n msg = map (\x -> toEnum (33 + (n + (fromEnum x) - 33) `mod` 93) :: Char) msg
這一次我會在ghci中運行,有:L asciiRot.hs
哦!我懂了!我已經將我的代碼從使用字符串更改爲僅使用字符。 我現在可以刪除該行,因爲不需要測試「空Char」 – MrNosco