There are three things wrong here.

First, the body of a try must be a complete expression. You have a 'let' without a body. (Could add e.g. "()" on line after the let.)

Second, there is no try-with-finally, only try-with and try-finally. (Could add a second try to match the finally.)

Third, the name 'stream' is not in scope in the finally.

All that said, what you really want instead of the 'finally' is a 'use', e.g.

1
2
3
4
5
6
7
8
9
10
11
12
 

open System.IO

let doSomething (fileName : string) =
    try 
        use stream = new FileStream(fileName,FileMode.Open,FileAccess.ReadWrite,FileShare.None)
        ()
    with 
        :? FileNotFoundException -> printfn "File not found."

By on 7/23/2009 1:08 AM ()

thanks brianmcn

By on 7/23/2009 9:19 PM ()

why this doesn't compile?

#light
open System

let AddMethod x y =
x + y

let multipleMethod x y =
x * y

let main() =
let System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch()
while( true ) do
Console.Write("x = ")
let x = Int32.Parse( Console.ReadLine())
Console.Write("y = ")
let y = Int32.Parse( Console.ReadLine())
sw.Start()
let z = AddMethod x y
Console.WriteLine("sum = "+ z.ToString())
let z = multipleMethod x y
Console.WriteLine("product = "+ z.ToString())
sw.Stop()
sw.Reset()

main()

By on 7/24/2009 11:12 PM ()

Two reasons, first you need

let sw = System.Diagnostics.Stopwatch() // get rid of words before 'sw' you had

and second, you have a space before the final 'main()' which you need to remove (it should not be indented).

By on 7/24/2009 11:28 PM ()

thank you brianmcn now it's ok

By on 7/25/2009 4:22 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