3
我跟在http://www.haskell.org/haskellwiki/Hitchhikers_guide_to_Haskell中的代碼,並且代碼(在第2章中)給出了一個錯誤。本教程中沒有提及作者姓名/電子郵件,所以我來這裏尋求建議。代碼如下,錯誤發生在「eof」字上。haskelwiki教程中的parsec錯誤
module Main where
import Text.ParserCombinators.Parsec
parseInput =
do dirs <- many dirAndSize
eof
return dirs
data Dir = Dir Int String deriving Show
dirAndSize =
do size <- many1 digit
spaces
dir_name <- anyChar `manyTill` newline
return (Dir (read size) dir_name)
main = do
input <- getContents
putStrLn ("Debug: got inputs: " ++ input)
謝謝。另外,從Main調用parseInput設置上下文。在上面的例子中,代碼正在構建,Main代碼來自以前的版本,並且不調用parseInput。當我修改下一節的主代碼段時,它工作。 – R71