You have a using
function available in the main library, but it is up to you whether you think this is more elegant:
match createSocket(hostEntry) with | Some socket -> using socket <| fun s -> sendRequest s uri.Host uri.PathAndQuery |> getResponse | None -> "Failed to open socket"
You can do it even further and pack the whole trick into one function:
module Option = let using func = Option.bind (fun disp -> using disp func) ... createSocket(hostEntry) |> Option.using (fun s -> sendRequest s uri.Host uri.PathAndQuery |> getResponse)
Although I do not remember that I ever felt the need to do it personally.
source share