Although I realize that .NET Core is intentionally stripped down relative to the full .NET platform, this method is necessary for idiomatic (i.e. single-assignment) programming with F# on Windows. Without it, the only way to close a file is to delete the File object which requires coping with nulls, a thing F# tries very hard to avoid.
Explicitly closing a file is often necessary on Windows due to its mandatory file locking semantics. For example, you cannot typically move or a file to another directory while a File object is open for writing on that file.
Lacking a Close() method, single-assignment code such as this:
open System.IO
let file = File.Create("myfile", ...)
... do stuff with file
file.Close()
... do something with myfile on disk
must be rewritten to use a mutable file object:
open System.IO
let mutable file = File.Create("myfile", ...)
... do stuff with file
file <- null
... do something with myfile on disk
Although that looks like a simple fix, now all the F# code dealing with file has to check for null before using the value, a very un-F# style of coding.
(Moved from [https://github.com/dotnet/cli/issues/1776])
Although I realize that .NET Core is intentionally stripped down relative to the full .NET platform, this method is necessary for idiomatic (i.e. single-assignment) programming with F# on Windows. Without it, the only way to close a file is to delete the
Fileobject which requires coping with nulls, a thing F# tries very hard to avoid.Explicitly closing a file is often necessary on Windows due to its mandatory file locking semantics. For example, you cannot typically move or a file to another directory while a
Fileobject is open for writing on that file.Lacking a
Close()method, single-assignment code such as this:must be rewritten to use a mutable
fileobject:Although that looks like a simple fix, now all the F# code dealing with
filehas to check fornullbefore using the value, a very un-F# style of coding.(Moved from [https://github.com/dotnet/cli/issues/1776])