hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

sequencing construct

Last post 07-14-2008, 5:43 by Julien. 1 replies.
Sort Posts: Previous Next
  •  07-14-2008, 4:20 6380

    sequencing construct

    The following code issues a warning FS0020: This expression should have type 'unit', but has type 'DirectoryInfo'.

    How can I sequence expressions to avoid such warnings?

    Thanks.

    #light
    open System.IO
    match Directory.Exists("c:/mydir") with
    | true -> ()
    | false ->
        Directory.CreateDirectory("c:/mydir")
        printfn "%s\n" "Directory created with success."

  •  07-14-2008, 5:43 6381 in reply to 6380

    Re: sequencing construct

    That's because of CreateDirectory... hence you may use :

    match Directory.Exists("c:/mydir") with
    | true -> ()
    | false ->
        ignore <| Directory.CreateDirectory("c:/mydir")              
        printfn "%s\n" "Directory created with success."

    or, equivalently,

    match Directory.Exists("c:/mydir") with
    | true -> ()
    | false -> 
        let _ = Directory.CreateDirectory("c:/mydir")              
        printfn "%s\n" "Directory created with success."

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems