2016-10-29 6 views
-3

にパースエラーを取得しています、私は入力 `MyFunctionを「上パースエラーを取得しています:は、なぜ私は次のコードでMyFunctionを

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 
+1

'myFunction'でエラーを修正すると、bindでdoブロックを終了できないため、' interactWith'でエラーが発生します。私はあなたのコードをより頻繁にコンパイルしようと勧めます。 –

+0

@ReinHenrichs私はそれにも気づき、私の答えに推定された修正を含めました。 – chepner

答えて

1

myFunction = idwhere句で定義された他のものと整列する必要があります。

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 
    |^
    | | 
    | here 
    | 
    not here 

よりインデントと同じコードは、それを明確にする:

import System.Environment (getArgs) 
interactWith function inputFile outputFile = do 
    input <- readFile inputFile 
    -- I assume a line break belongs here 
    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 
+0

私の更新されたコードを確認し、あなたが言ったことは、まだ解析エラーを取得しました。 –

+1

@AliTotoこれで、代わりに 'args'と揃えました。インデントに複数のスペースを使用することができます。 – molbdnilo

+0

'myFunction'は' do'ブロックの一部ではありません。これはあなたが 'args'で整列して言っていることです。 – chepner

0

をHaskellで、これを行うには悪い習慣である:それはにISNので、これはエラーが発生する可能性があり

where a = x 
    b = y 

同じ列に並んでいないので、CRNLをつけてください:

where 
    a = x 
    b = y 
関連する問題