在下面的代码中,我在输入`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
答案 0 :(得分:2)
myFunction = id
需要与where
子句中定义的其他内容对齐。
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
答案 1 :(得分:0)
在haskell中,执行此操作是不好的做法:
where a = x
b = y
这可能导致错误,因为它没有排列相同,所以请在以下地址后进行CRNL:
where
a = x
b = y