New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use on multiple binding (`let x, y = ...` compiles, but `use x, y = ..` not) #693

Open
dzmitry-lahoda opened this Issue Sep 14, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@dzmitry-lahoda

dzmitry-lahoda commented Sep 14, 2018

Use on multiple binding (let x, y = ... compiles, but use x, y = .. not)

I propose to have multi use.

Call to public static void CreateWithSwapChain(DriverType driverType, DeviceCreationFlags flags, SwapChainDescription swapChainDescription, out Device device, out SwapChain swapChain) as

    let device, swapChain = SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.None, chainSwapDescription)
    device.Dispose()
    swapChain.Dispose()

replaced with

use device, swapChain = SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.None, chainSwapDescription)

The existing way of approaching this problem in F# is use' bindings must be of the form 'use <var> = <expr>' error.

Pros and Cons

The advantages of making this adjustment to F# are better coding to SharpDX and similar complex native code wrappers, use to support more of let.

The disadvantages of making this adjustment to F# is that case can be to narrow to support.

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • [X ] This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this
@cartermp

This comment has been minimized.

Show comment
Hide comment
@cartermp

cartermp Oct 3, 2018

Member

I think this would be a good and sensible addition. Speaking with @jaredpar, this sounded like something that would also be supported in the corresponding C# feature proposal.

Member

cartermp commented Oct 3, 2018

I think this would be a good and sensible addition. Speaking with @jaredpar, this sounded like something that would also be supported in the corresponding C# feature proposal.

@dzmitry-lahoda dzmitry-lahoda changed the title from Use on multiplae binding (`let x, y = ...` compiles, but `use x, y = ..` not) to Use on multiple binding (`let x, y = ...` compiles, but `use x, y = ..` not) Oct 3, 2018

@jaredpar

This comment has been minimized.

Show comment
Hide comment
@jaredpar

jaredpar Oct 3, 2018

CC @chsienki

The corresponding C# proposal is pattern based dispose. It would essentially allow using var x to be allowed whenever x.Dispose() would be a legal expression. That could be combined with tuples in the following way:

public static void Dispose<T1, T2>(ref this (T1, T2) tuple) 
  where T1 : IDisposable
  where T2 : IDisposable { 
  tulpe.Item1.Dispose();
  tuple.Item2.Dispose();
}

Such a method would then allow tuples, where the items were IDisposable to be usable in a using statement or block.

jaredpar commented Oct 3, 2018

CC @chsienki

The corresponding C# proposal is pattern based dispose. It would essentially allow using var x to be allowed whenever x.Dispose() would be a legal expression. That could be combined with tuples in the following way:

public static void Dispose<T1, T2>(ref this (T1, T2) tuple) 
  where T1 : IDisposable
  where T2 : IDisposable { 
  tulpe.Item1.Dispose();
  tuple.Item2.Dispose();
}

Such a method would then allow tuples, where the items were IDisposable to be usable in a using statement or block.

@dsyme

This comment has been minimized.

Show comment
Hide comment
@dsyme

dsyme Oct 12, 2018

Collaborator

Don't you think it's easier to just use a helper? Baking this into the compiler gives a more complex translation of use which feels awkward, given the workaround is so simple

    use device, swapChain = Dispose2(SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.None, chainSwapDescription))
Collaborator

dsyme commented Oct 12, 2018

Don't you think it's easier to just use a helper? Baking this into the compiler gives a more complex translation of use which feels awkward, given the workaround is so simple

    use device, swapChain = Dispose2(SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.None, chainSwapDescription))

@dsyme dsyme added the probably not label Oct 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment