I have the following line of code which when compiled with GHC it goes without a hitch:
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"
But when I run it through the cabal build process, it dumps out the following error.
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?
I can see the additional semicolon in the error but I don’t understand where that comes from.
Here is my cabal configuration file:
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
UPDATE
With correct indentation for 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"
I get a semicolon after check now as well:
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?
Your indentation is incorrect, but it works when you use the raw GHC compiler because it automatically turns on the syntactic extension mentioned in the error message (
DoAndIfThenElse).In Cabal, you have to specify the language extensions that you use manually, either at the top of your code files, or in your Cabal files; otherwise, they will not be enabled by the compiler.
One correct version of the indentation for if-clauses is like this:
You have to keep the
thenpart and theelsepart at deeper indentation levels than the block they’re a part of.