我有以下代码行,当使用 GHC 编译时,它会顺利进行:
addRDF c (Just (FILE)) = do
(_:file:_) <- getArgs
check <- doesFileExist file
if check then do rdfG <- TLI.readFile file >>= (return . parseN3fromText)
case rdfG of (Left s) -> putStrLn s
(Right g) -> storeRDF c g
else do putStrLn "Specified files does not exist"
但是当我通过 cabal 构建过程运行它时,它会输出以下错误。
Repository/Adder.hs:46:35:
Unexpected semi-colons in conditional:
if check then do { rdfG <- TLI.readFile file
>>=
(return . parseN3fromText);
case rdfG of {
(Left s) -> putStrLn s
(Right g) -> storeRDF c g } }; else do { putStrLn
"Specified files does not exist" }
Perhaps you meant to use -XDoAndIfThenElse?
我可以在错误中看到额外的分号,但我不明白它来自哪里。
这是我的 cabal 配置文件:
cabal-version: >= 1.2
build-type: Simple
library
build-depends:
base,
containers,
HTTP >= 4000.2.2,
directory >= 1.1.0.0,
text >= 0.11.1.13,
swish >= 0.6.5.2
exposed-modules: Repository.Adder, Repository.Configuration
ghc-options: -Wall
executable repository-add
main-is: repository-add.hs
build-depends:
MissingH,
swish >= 0.6.5.2,
split >= 0.1.4.2
ghc-options: -Wall
更新
使用正确的缩进if
:
addRDF c (Just (FILE)) = do (_:file:_) <- getArgs
check <- doesFileExist file
if check
then do rdfG <- TLI.readFile file >>= (return . parseN3fromText)
case rdfG of (Left s) -> putStrLn s
(Right g) -> storeRDF c g
else do putStrLn "Specified files does not exist"
我现在也得到一个分号check
:
Repository/Adder.hs:46:35:
Unexpected semi-colons in conditional:
if check; then do { rdfG <- TLI.readFile file
>>=
(return . parseN3fromText);
case rdfG of {
(Left s) -> putStrLn s
(Right g) -> storeRDF c g } }; else do { putStrLn
"Specified files does not exist" }
Perhaps you meant to use -XDoAndIfThenElse?