Tôi có dòng mã sau đây mà khi biên dịch với GHC nó đi mà không có một xô:bất ngờ dấu chấm phẩy trong điều kiện
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"
Nhưng khi tôi chạy nó thông qua quá trình xây dựng cabal, nó bãi ra như sau lỗi.
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?
Tôi có thể thấy dấu chấm phẩy bổ sung trong lỗi nhưng tôi không hiểu vị trí đó đến từ đâu.
Dưới đây là tập tin của tôi cabal cấu hình:
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
CẬP NHẬT
Với thụt đầu dòng chính xác cho 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"
tôi nhận được một dấu chấm phẩy sau check
bây giờ là tốt:
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?
Thú vị, tôi đã nghĩ về điều gì đó tương tự nhưng thêm 'mở rộng: DoAndIfThenElse' vào tệp cabal của tôi không có bất kỳ ảnh hưởng nào. – mhitza
Đã cập nhật bài đăng của tôi vì bản sửa lỗi thụt đầu dòng không giải quyết được sự cố: | – mhitza
@mhitza: Tôi tin rằng tôi đã sửa vấn đề thụt đầu dòng nếu-thì-khác. –