Of Code and Me

Somewhere to write down all the stuff I'm going to forget and then need

F# warning FS0020: October 31, 2008

Filed under: Uncategorized — Rupert Bates @ 10:27 pm
Tags:

Something interesting I found out today:

I’ve seen this warning quite a lot when programming in F:

“warning FS0020: This expression should have type ‘unit’, but has type ‘SomeType’.”

for instance in something I was coding today:

let CreateDirectory d =
    printfn "creating directory %s" d
    Directory.CreateDirectory (destDir + d) //warning FS0020
    () //this function has to return unit in order to be used with Array.iter

Array.iter CreateDirectory dirs

The way to get rid of this warning is to pipeline the result of the function which is causing the warning into the ignore function as follows:

Directory.CreateDirectory (destDir + d) |> ignore

and hey presto your warning disappears.

Advertisements
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s