0

次のエラーが表示されます...

入力 'args' の解析エラー

...次のコードをコンパイルしようとしている間:

import System.Environment (getArgs)

interactWith function inputFile outputFile = do 
    input <- readFile inputFile
    writeFile outputFile (function input)

main = mainWith myFunction   
    where mainWith function = do
        args <- getArgs  
        case args of
            [input,output] -> interactWith function input output 
            _ -> putStrLn "error: exactly two arguments needed"

        -- replace "id" with the name of our function below 
        myFunction = id

このコードは、 Real World Haskellの第 4 章から取られています。

4

2 に答える 2

2

問題はインデントでした。本では、インデントを正しく解釈できませんでした。コードは次のようになります。

import System.Environment (getArgs)

interactWith function inputFile outputFile = do 
    input <- readFile inputFile
    writeFile outputFile (function input)

main = mainWith myFunction   
    where 
        mainWith function = do
            args <- getArgs  
            case args of
                [input,output] -> interactWith function input output 
                _ -> putStrLn "error: exactly two arguments needed"

        -- replace "id" with the name of our function below 
        myFunction = id

Haskell の学習で私が抱えている大きな問題の 1 つは、あいまいなコンパイル エラーです。

于 2013-04-21T15:29:14.493 に答える
0

質問のコードのインデントは正しいです。コードに a を挿入した可能性があります。エディターですべてのタブを 4 つのスペースに置き換えるよう強制する方法は多数あります。

于 2013-04-21T16:44:50.843 に答える