Simon Hayward
Simon Hayward

Reputation: 724

A save function in F# that does not want to run

I have borrowed the following save function to save values of any type to a given file (cheers to John Harrop, writer of F# for scientists).

    open System.IO
    open System.Runtime.Serialization.Formatters.Binary

    let save filename x =
       use stream =
         new FileStream(filename, FileMode.Create)
       (new BinaryFormatter()).Serialize(stream, x);;

But F# is telling me that there is no body for the "use" part of the function. I seems to not like the final line but the intellisense is not giving me an error message when I hover.

Do I need to declare another namespace?

Can anyone advise? Very grateful for any help.

Upvotes: 0

Views: 182

Answers (1)

Daniel
Daniel

Reputation: 47914

Works on my machine! :-) If you're typing this directly into FSI try putting it in a script file and using 'Send to Interactive'. If you're not, remove ;; on the last line.

Upvotes: 3

Related Questions