You need to use else false rather than just false. That way, the if's body and the else's body have type bool, and so does the whole if/then/else expression.

Otherwise, the function would conditionally execute the if's body but always return false. This means that the if's body would need to have type unit, not bool, which is the error that you're seeing.

By on 8/16/2011 10:08 AM ()

you have an if-then but you want an if-then-else

1
2
3
4
5
if ... then
    ...
    true
else
    false

if-then-else is an expression, whereas the body of an if-then is just a statement (unit-returning expression whose result is discarded)

By on 8/16/2011 10:05 AM ()

Add explicit 'else' branch to the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
            if not (File.Exists(targetFile)) then

                printf "Copying %s\r\n" sourceFile

                File.Copy(sourceFile, targetFile)

                File.SetAttributes(targetFile, FileAttributes.Archive)

                true

            else

                false

If there is no explicit else branch, its type is unit.

By on 8/16/2011 10:04 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper