What does this error message " Unexpected do block in function application" mean?

NM00

I'm trying to compile this function but I get an error. What is it that Haskell is not happy about?

copyFile :: FilePath ->  FilePath -> IO()
copyFile fromFile toFile = 
     do c <- readFile fromFile
    writeFile toFile c 

Unexpected do block in function application: do c <- readFile fromFile You could write it with parentheses Or perhaps you meant to enable BlockArguments?

Willem Van Onsem

The indentation is not entirely correct, and as a result the compiler parses this as if the do is only applied to the c <- readFile fromFile, and not to the writeFile.

copyFile :: FilePath -> FilePath -> IO()
copyFile fromFile toFile = do
    c <- readFile fromFile
    writeFile toFile c

or shorter:

copyFile :: FilePath -> FilePath -> IO()
copyFile fromFile toFile = readFile fromFile >>= writeFile toFile

That being said, I strongly recommend to use copyFile :: FilePath -> FilePath -> IO () or copyFileWithMetadata :: FilePath -> FilePath -> IO () instead. That way you do not load the content of the file in memory (the file might be larger than the amount of available memory). Some file systems could improve the efficiency significantly, for example by only adding an extra reference to the file, and making a real copy in case one of the two files is modified.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Unexpected do block in function application involving ReadMode what does mean this message?

What does this error message mean?

What does this Pdesurf error message mean?

What does this BSOD error message mean?

What does this logcat error message mean?

What does the GCC error message, "Error: unsupported for `mov'", mean?

What does the PHP error message "Notice: Use of undefined constant" mean?

What does this GHC.Generic function signature error message mean?

What does the “slot doesn't exist” error message mean?

What does this Google Play APK publish error message mean?

What does `(&)()` mean in a C++ compiler error message

What does the error message 0xC000041D mean?

What does `line 19: 12364 Killed` mean in crontab error message?

What does the error message "setoid rewrite failed: UNDEFINED EVARS" mean?

What does it mean to 'move this variable directly inside useEffect' in this error message?

What does [I mean in a scala ClassCastException error message?

What does the error message "Column name must not be duplicated" mean in this context

What does a TPM error message when booting mean?

What does Amazon SES Error message: Missing '"' mean?

what does this clamAV message mean?

What does this commit message mean?

What does this terminal message mean?

What does this error mean?

In jsfiddle, what does the runtime error message "error" : "key missing: title" mean?

Error 57 - what does it mean?

What does this dtrace error mean?

What does _("write error") mean?

What does this Java error mean?

What does this valgrind error mean?

TOP Ranking

HotTag

Archive